目录
JavaScript V8模式
JavaScript node模式
题目类型一:A+B
第一题:输入包括两个正整数a,b(1 <= a, b <= 1000),输入数据包括多组。
第二题:输入第一行包括一个数据组数t(1 <= t <= 100),接下来每行包括两个正整数a,b(1 <= a, b <= 1000)
第三题:输入包括两个正整数a,b(1 <= a, b <= 10^9),输入数据有多组, 如果输入为0 0则结束输入
第四题:输入数据包括多组。每组数据一行,每行的第一个整数为整数的个数n(1 <= n <= 100), n为0的时候结束输入。接下来n个正整数,即需要求和的每个正整数。
第五题:输入的第一行包括一个正整数t(1 <= t <= 100), 表示数据组数。接下来t行, 每行一组数据。每行的第一个整数为整数的个数n(1 <= n <= 100)。接下来n个正整数, 即需要求和的每个正整数。
第六题:输入数据有多组, 每行表示一组输入数据。每行的第一个整数为整数的个数n(1 <= n <= 100)。接下来n个正整数, 即需要求和的每个正整数。
第七题:输入数据有多组, 每行表示一组输入数据。每行不定有n个整数,空格隔开。(1 <= n <= 100)。
题目类型二:字符串排序
第一题:输入有两行,第一行n 第二行是n个字符串,字符串之间用空格隔开
第二题:多个测试用例,每个测试用例一行。 每行通过空格隔开,有n个字符,n<100
第三题:多个测试用例,每个测试用例一行。 每行通过,隔开,有n个字符,n<100
注意:自测本地AC,提交0
练习试题:牛客竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ (nowcoder.com)
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
let number = deadline(); // 第一行是输入的数据的组数
while(line = await readline()){
// 操作数据的逻辑
}
}()
输入:
1 5
10 20输出:
6
30
V8:
while(line=readline()){
let lines = line.split(' ');
let a = parseInt(lines[0]);
let b = parseInt(lines[1]);
print(a+b);
}
node:
// 设定好如何读数据
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
let number = readline();
while(line = await readline()){
let tokens = line.split(' ');
let a = parseInt(tokens[0]);
let b = parseInt(tokens[1]);
console.log(a + b);
}
}()
输入:
2
1 5
10 20输出:
6
30
V8:
let r = parseInt(readline()); // 读首行,确定行数
for (let i=0; i parseInt(item)); // 将每一行的数据字符串切分成数字并存入数组arr
let [a,b] = arr; // 解构出a和b
print(a+b)
}
node:
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
let number = readline();
while(line = await readline()){
let tokens = line.split(' ');
let a = parseInt(tokens[0]);
let b = parseInt(tokens[1]);
console.log(a + b);
}
}()
输入:
1 5
10 20
0 0输出:
6
30
V8:
let line = '';
// 从第一行开始,读取每一行数组字符串
while (line = readline()) {
// 将每一行的数据字符串转换成数字并以数组items的形式存储
let items = line.split(" ").map(item=>parseInt(item));
// 如果读取到输入为0 0
if (items[0] === 0 && items[1] ===0) {
// 以break退出循环读入航
break;
}
print(items[0]+items[1])
}
node:
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
while(line = await readline()){
let tokens = line.split(' ');
let a = parseInt(tokens[0]);
let b = parseInt(tokens[1]);
if (a === 0 && b === 0) {
break;
}
console.log(a + b);
}
}()
输入:
4 1 2 3 4
5 1 2 3 4 5
0输出:
10
15
V8:
let line = "";
while (line = readline()) {
let items = line.split(' ').map(item => parseInt(item));
if (items[0] === 0) {
break;
}
let sum = 0;
for (let i=0; i (await iter.next()).value;
void async function () {
// Write your code here
while(line = await readline()){
let tokens = line.split(' ').map(item => parseInt(item));
let sum = 0;
if (tokens[0] === 0) {
break;
}
for (let i=1; i
输入:
2
4 1 2 3 4
5 1 2 3 4 5输出:
10
15
V8:
let t = parseInt(readline());
let line = '';
while(t--){
line = readline();
let items = line.split(' ').map(item=>parseInt(item));
let sum = 0;
for (let i=0; i (await iter.next()).value;
void async function () {
// Write your code here
let number = readline();
while(line = await readline()){
let tokens = line.split(' ').map(item => parseInt(item));
let sum = 0;
for (let i=1; i
输入:
4 1 2 3 4
5 1 2 3 4 5输出:
10
15
V8:
let line = "";
// 一直读数据
while (line = readline()){
let sum = 0;
let items = line.split(" ").map(item => parseInt(item));
for (i=0; i (await iter.next()).value;
void async function () {
// Write your code here
while(line = await readline()){
let tokens = line.split(' ').map(item => parseInt(item));
let sum =0;
for (let i=1; i
输入:
1 2 3
4 5
0 0 0 0 0输出:
6
9
0
V8:
let line = "";
while (line = readline()) {
let sum = 0;
let items = line.split(" ").map(item => parseInt(item));
for (i=0; i (await iter.next()).value;
void async function () {
// Write your code here
while(line = await readline()){
let tokens = line.split(' ').map(item => parseInt(item));
let sum = 0;
for (let i=0; i
输入:
5
c d a bb e输出:
a bb c d e
V8:
let t = readline(); // 第一行,字符串个数
let lines = readline().split(" ").map(line => line);
print(lines.sort().join(" "))
node:
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// Write your code here
let number = readline();
while ((line = await readline())) {
let tokens = line.split(" ");
console.log(tokens.sort().join(" "));
}
})();
输入:
a c bb
f dddd
nowcoder输出:
a bb c
dddd f
nowcoder
V8:
let lines = "";
while (lines = readline()) {
let items = lines.split(" ").map(item => item);
print(items.sort().join(" "))
}
node:
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
while(line = await readline()){
let tokens = line.split(' ');
console.log(tokens.sort().join(" "))
}
}()
输入:
a,c,bb
f,dddd
nowcoder输出:
a,bb,c
dddd,f
nowcoder
V8:
let lines = "";
while (lines = readline()) {
let items = lines.split(",").map(item => item);
print(items.sort().join(","));
}
node:
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
while(line = await readline()){
let tokens = line.split(',');
console.log(tokens.sort().join(","))
}
}()
可能是因为
1.你对题目理解错了,你的代码只过了样例或你自己的数据
2.你的代码逻辑有问题,你的代码只过了样例或你自己的数据
总之就是你的代码只是过了样例和自测数据,后台的测试数据你根本不可见,要多自己思考。