欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

codeup之A+B 输入输出练习I 、II 、III、IV、V、VI、VII、VIII(黑盒测试

发布时间:2025/5/22 编程问答 49 如意码农
生活随笔 收集整理的这篇文章主要介绍了 codeup之A+B 输入输出练习I 、II 、III、IV、V、VI、VII、VIII(黑盒测试 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

不建议做,掌握书上几种情况即可,题简单又重复

I Description

你的任务是计算a+b。这是为了acm初学者专门设计的题目。你肯定发现还有其他题目跟这道题的标题类似,这些问题也都是专门为初学者提供的。

Input

输入包含一系列的a和b对,通过空格隔开。一对a和b占一行。

Output

对于输入的每对a和b,你需要依次输出a、b的和。
如对于输入中的第二对a和b,在输出中它们的和应该也在第二行。

Sample Input Copy

1 5
10 20

Sample Output Copy

6
30

solution

#include <stdio.h>
int main(){
int a, b;
while(scanf("%d %d", &a, &b) != EOF)
printf("%d\n", a + b);
return 0;
}

II Description

你的任务是计算a+b。

Input

第一行是一个整数N,表示后面会有N行a和b,通过空格隔开。

Output

对于输入的每对a和b,你需要在相应的行输出a、b的和。
如第二对a和b,对应的和也输出在第二行。

Sample Input Copy

2
1 5
10 20

Sample Output Copy

6
30

solution

#include <stdio.h>
int main(){
int a, b, n;
scanf("%d", &n);
while(n--){
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
} return 0;
}

III Description

你的任务是计算a+b。

Input

输入中每行是一对a和b。其中会有一对是0和0标志着输入结束,且这一对不要计算。

Output

对于输入的每对a和b,你需要在相应的行输出a、b的和。
如第二对a和b,他们的和也输出在第二行。

Sample Input Copy

1 5
10 20
0 0

Sample Output Copy

6
30

solution

#include <stdio.h>
int main(){
int a, b;
while(scanf("%d %d", &a, &b), a || b){
printf("%d\n", a + b);
} return 0;
}

IV Description

你的任务是计算若干整数的和。

Input

每行的第一个数N,表示本行后面有N个数。

如果N=0时,表示输入结束,且这一行不要计算。

Output

对于每一行数据需要在相应的行输出和。

Sample Input Copy

4 1 2 3 4
5 1 2 3 4 5
0

Sample Output Copy

10
15

solution

#include <stdio.h>
int main(){
int n, sum, x;
while(scanf("%d", &n), n){
sum = 0;
for(int i = 0; i < n; i++){
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
} return 0;
}

V Description

你的任务是计算若干整数的和。

Input

输入的第一行是一个正数N,表示后面有N行。每一行的第一个数是M,表示本行后面还有M个数。

Output

对于每一行数据需要在相应的行输出和。

Sample Input Copy

2
4 1 2 3 4
5 1 2 3 4 5

Sample Output Copy

10
15

solution

#include <stdio.h>
int main(){
int n, m, sum, x;
scanf("%d", &n);
while(n--){
scanf("%d", &m);
sum = 0;
for(int i = 0; i < m; i++){
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
} return 0;
}

VI Description

你的任务是计算若干整数的和。

Input

每行的第一个数N,表示本行后面有N个数。

Output

对于每一行数据需要在相应的行输出和。

Sample Input Copy

4 1 2 3 4
5 1 2 3 4 5

Sample Output Copy

10
15

solution

#include <stdio.h>
int main(){
int n, sum, x;
while(scanf("%d", &n) != EOF){
sum = 0;
for(int i = 0; i < n; i++){
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
} return 0;
}

VII Description

你的任务是计算两个整数的和。

Input

输入包含若干行,每行输入两个整数a和b,由空格分隔。

Output

对于每组输入,输出a和b的和,每行输出后接一个空行。

Sample Input Copy

1 5
10 20

Sample Output Copy

6

30

solution

#include <stdio.h>
int main(){
int a, b;
while(scanf("%d %d", &a, &b) != EOF){
printf("%d\n\n", a + b);
} return 0;
}

VIII Description

你的任务是计算若干整数的和。

Input

输入的第一行为一个整数N,接下来N行每行先输入一个整数M,然后在同一行内输入M个整数。

Output

对于每组输入,输出M个数的和,每组输出之间输出一个空行。

Sample Input Copy

3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3

Sample Output Copy

10

15

6

solution

#include <stdio.h>
int main(){
int n, m, sum, x;
scanf("%d", &n);
while(n--){
scanf("%d", &m);
sum = 0;
for(int i = 0; i < m; i++){
scanf("%d", &x);
sum += x;
}
printf("%d\n\n", sum);
} return 0;
}

总结

以上是生活随笔为你收集整理的codeup之A+B 输入输出练习I 、II 、III、IV、V、VI、VII、VIII(黑盒测试的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。