js input/output problem in saima.com

Jiumin, my family, because of the use of js (v8) environment, the input data on Saima.com or Niukee.com was incorrectly obtained, and the pass rate of the entire code was 0!!! Tears of sincere regret were shed. Swear to complete the input and output. . .

Game code network input:


Use read_line() to obtain input data

Some code examples are as follows:

1. Input form:

输入样例:
3
3 3 2

analyze:

  • Enter a number on the first line
  • Enter an array on the second line
let len = read_line();  //获取第一个输入字符‘3’
let arr = []; //声明数组arr,来保存输入的数组
arr = read_line().split(' '); //获取第二行数据:'3' '3' '2',  使用split,以空格作为分隔将字符串转换为一个数组。['3', '3', '2']
for(let i = 0; i < arr.length; i++) {
    
    
	arr[i] = parseInt(arr[i]); //将数组中的元素转换为数字
}
// arr就是最终需要获取的数组: [3,3,2]

Note in particular : the objects obtained with read_line() are all string types and need to be converted

Niuke.com input

Guess you like

Origin blog.csdn.net/Matcha_ice_cream/article/details/124258351
Recommended