如何读取nodejs中的不同用户输入?

问题描述:

我最近在HackerEarth上检查了javascript(nodejs)。它有以下代码已经写入。如何读取nodejs中的不同用户输入?

function main(input) { 
//Enter your code here 

}

process.stdin.resume(); 
process.stdin.setEncoding("utf-8"); 
var stdin_input = ""; 

process.stdin.on("data", function (input) { 
stdin_input += input; 
}); 

process.stdin.on("end", function() { 
    main(stdin_input); 
}); 

我如何读取测试例样品的输入,如

A)First line contains no. of test cases and size of array. 
Next T lines contains array content. 
- 3 4 
- 32 33 12 2 
- 1 23 34 3 
- 65 2 21 11 

B)The first line contains the number of testcases, T. 
Next, T lines follow each containing a long string S. 
- 3 
- SUVKITSU 
- 651SUVOMN 
- SAHJ8HSAU6 

所以,一切的一切,我的问题是如何读取输入整数,字符串和在javascript(nodeJs)中进行竞争性编程的数组?

查看JavaScript的字符串方法,如.split().substr()

+0

.split()&.substr()将从主字符串中分离或提取特定长度的字符串。我想要的是读取主字符串。 –