简体   繁体   English

给定两个正整数 N 和 X,其中 N 是患者总数,X 是新患者到达后的持续时间(以分钟为单位)

[英]Given two positive integers N and X, where N is the number of total patients and X is the time duration(in minutes) after which a new patient arrives

Given two positive integers N and X, where N is the number of total patients and X is the time duration(in minutes) after which a new patient arrives.给定两个正整数 N 和 X,其中 N 是患者总数,X 是新患者到达后的持续时间(以分钟为单位)。 Also, doctor will give only 10 minutes to each patient.此外,医生只会给每位患者 10 分钟的时间。 The task is to calculate the time (in minutes) the last patient needs to wait.任务是计算最后一个病人需要等待的时间(以分钟为单位)。

Input:输入:

The first line of input contains the number of test cases T. The next subsequent lines denote the total number of patients N and time interval X(in minutes) in which the next patients are visiting.输入的第一行包含测试用例 T 的数量。接下来的后续行表示患者总数 N 和下一位患者访问的时间间隔 X(以分钟为单位)。

Output: Output:

Output the waiting time of last patient. Output 最后一个病人的等待时间。

Constraints:约束:

1 <= T <= 100 1 <= T <= 100

0 <= N <= 100 0 <= ñ <= 100

0 <= X <= 30 0 <= X <= 30

Example:例子:

Input:输入:

5 5个

4 5 4 5

5 3 5 3

6 5 6 5

7 6 7 6

8 2 8 2

Output: Output:

15 15

28 28

25 25

24 24

56 56

need in javascript. I know the python code.需要输入 javascript。我知道 python 代码。 but needs to convert into javascript. anyone can help me.但需要转换成 javascript。任何人都可以帮助我。

 n=int(input()) for i in range(n): t=0 a,b=map(int,input().split()) if a==1: print(t) else: t=(a-1)*(10-b) print(t)

If by Javascript you mean Node.js, this is the code.如果 Javascript 你的意思是 Node.js,这就是代码。 Due to Node.js's asynchronous nature, handling user input is a bit tedious.由于 Node.js 的异步特性,处理用户输入有点乏味。

const readline = require("readline");

async function solve(n) {
    for (let i = 0; i < n; i++) {  // for i in range(n)
        let t = 0;
        let inputs = (await readInput()).split(" ");
        let a = inputs[0]; let b = inputs[1];  // a, b = map ...

        if (a === 1) {
            console.log(t);
        } else {
            t = (a - 1) * (10 - b);
            console.log(t);
        }

    }
}

function readInput() {
    // Creates an interface for input and output
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout,
    });

    // Returns the input
    return new Promise((resolve) => rl.question("Input: ", (ans) => {
        rl.close();
        resolve(ans);
    }))
}

async function main() {
    await solve(await readInput());
}

main().then(_ => console.log("Done"));
    class Main {
static int waittime(int n ,int x){
    int wait1 = x*(n-1);  //total time till the last patient arrived
int wait2 = (n-1)*10; //total time doctor take to see all patient except last
    int wait = wait2-wait1;//total wait time
    if(wait<0)
      wait = 0;
 return wait;
}
public static void main (String[] args) {
                  Scanner sc = new Scanner(System.in);
                  int t = sc.nextInt(); // t is total test case
                  int n ,x;
                  int arr[] = new int[t];
                  for(int i=0;i<t;i++){
                      n = sc.nextInt();
                      x = sc.nextInt();
                      arr[i] = waittime(n,x); // storing wait time for each 
                                               //  test case 
                  }
                  for(int i=0;i<t;i++){
                      System.out.println(arr[i]);
                  }
}

} }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有一种算法,给定一个整数列表,返回一个大小为 N 的整数列表,其中总值为 V±100? - Is there an algorithm that, given a list of integers, returns a list of integers of size N where the total value is V±100? 在Javascript中运行“x”时间后将停止“n”时间的计时器任务 - Timer task that will stop for an "n" time after runs for "x" time in Javascript 如果为正数,则返回“ +” + n - return '+' +n if positive number 给定一个包含 n 个整数的列表 arr[0..(n-1)],确定其中总和为 k 的不同元素对的数量 - Given a list of n integers arr[0..(n-1)], determine the number of different pairs of elements within it which sum to k 将数字 (x) 乘以给定数字 (y) 一定次数 (n) 的函数 - Function to multiply a number (x) by a given number (y) a certain number of times (n) 我如何使它更有效-考虑分数 n/d,其中 n 和 d 是正整数 - How do I make this more efficient- Consider the fraction, n/d, where n and d are positive integers 返回数字 x 的前 n 个倍数 - return the first n multiples of the number x 如何将javascript中的数字n分成x部分,其中所有部分的总和等于数字? - How to divide number n in javascript into x parts, where the sum of all the parts equals the number? 给定N个步数和M个最大可能步数时,返回该人可以从0级到N级(更高)的可能序列总数 - When given N num of steps and M max possible steps return the total number possible sequences where the person can go (higher) from level 0 to level N 您可以使用 JavaScript 中的对象在 O(N)(线性)时间内对正整数进行排序吗? - Can you sort positive integers in O(N) (linear) time using an object in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM