![](/img/trans.png)
[英]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?
[英]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.