繁体   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

给定两个正整数 N 和 X,其中 N 是患者总数,X 是新患者到达后的持续时间(以分钟为单位)。 此外,医生只会给每位患者 10 分钟的时间。 任务是计算最后一个病人需要等待的时间(以分钟为单位)。

输入:

输入的第一行包含测试用例 T 的数量。接下来的后续行表示患者总数 N 和下一位患者访问的时间间隔 X(以分钟为单位)。

Output:

Output 最后一个病人的等待时间。

约束:

1 <= T <= 100

0 <= ñ <= 100

0 <= X <= 30

例子:

输入:

5个

4 5

5 3

6 5

7 6

8 2

Output:

15

28

25

24

56

需要输入 javascript。我知道 python 代码。 但需要转换成 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)

如果 Javascript 你的意思是 Node.js,这就是代码。 由于 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM