牛客网ACM模式输入输出

凡事预则立,不预则废。

练习地址

A + B (1)

1
2
3
4
5
6
while(line = readline()){
let lines = line.split(' ');
let a = parseInt(lines[0]);
let b = parseInt(lines[1]);
print(a+b);
}

A + B (2)

1
2
3
4
5
6
7
let len = readline();
while(len--){
let lines = readline().split(' ');
let a = parseInt(lines[0]);
let b = parseInt(lines[1]);
print(a+b);
}

A + B (3)

1
2
3
4
5
6
7
while(line = readline()){
let lines = line.split(' ');
let a = parseInt(lines[0]);
let b = parseInt(lines[1]);
if(a===0 && b===0) break;
print(a+b);
}

A + B (4)

1
2
3
4
5
6
7
8
9
10
while(line = readline()){
let lines = line.split(' ');
let len = parseInt(lines[0]);
if(len === 0) break;
let res = 0;
for(let i=1;i<=len;++i){
res += parseInt(lines[i]);
}
print(res);
}

A + B (5)

1
2
3
4
5
6
7
8
9
10
let len = readline();
while(len--){
let lines = readline().split(' ');
let end = parseInt(lines[0]);
let res = 0;
for(let i=1;i<=end;++i){
res += parseInt(lines[i]);
}
print(res);
}

A + B (6)

1
2
3
4
5
6
7
8
9
while(line = readline()){
let lines = line.split(' ');
let len = (lines[0]);
let sum = 0;
while(len--){
sum += parseInt(lines[len+1]);
}
print(sum);
}

A + B (7)

1
2
3
4
5
6
7
8
9
10
11
12
while(line = readline()){
lines = line.split(' ');
if(parseInt(lines[0])===0){
print(0);
break;
}
let sum = 0;
for(let i=0;i<lines.length;++i){
sum += parseInt(lines[i]);
}
print(sum);
}

字符串排序(1)

1
2
3
let len = readline();
let arr = readline().split(' ');
print(arr.sort().join(' '));

字符串排序(2)

1
2
3
4
while(line = readline()){
lines = line.split(' ');
print(lines.sort().join(' '));
}

字符串排序(3)

1
2
3
4
while(line = readline()){
lines = line.split(',');
print(lines.sort().join(','));
}
文章作者: qinwei
文章链接: https://qw-null.github.io/2022/02/14/牛客网ACM模式输入输出/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 QW's Blog