codeup之A+B 输入输出练习I 、II 、III、IV、V、VI、VII、VIII(黑盒测试
不建議做,掌握書上幾種情況即可,題簡單又重復
I Description
你的任務是計算a+b。這是為了acm初學者專門設計的題目。你肯定發(fā)現(xiàn)還有其他題目跟這道題的標題類似,這些問題也都是專門為初學者提供的。
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
第一行是一個整數(shù)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
你的任務是計算若干整數(shù)的和。
Input
每行的第一個數(shù)N,表示本行后面有N個數(shù)。
如果N=0時,表示輸入結束,且這一行不要計算。
Output
對于每一行數(shù)據(jù)需要在相應的行輸出和。
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
你的任務是計算若干整數(shù)的和。
Input
輸入的第一行是一個正數(shù)N,表示后面有N行。每一行的第一個數(shù)是M,表示本行后面還有M個數(shù)。
Output
對于每一行數(shù)據(jù)需要在相應的行輸出和。
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
你的任務是計算若干整數(shù)的和。
Input
每行的第一個數(shù)N,表示本行后面有N個數(shù)。
Output
對于每一行數(shù)據(jù)需要在相應的行輸出和。
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
你的任務是計算兩個整數(shù)的和。
Input
輸入包含若干行,每行輸入兩個整數(shù)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
你的任務是計算若干整數(shù)的和。
Input
輸入的第一行為一個整數(shù)N,接下來N行每行先輸入一個整數(shù)M,然后在同一行內(nèi)輸入M個整數(shù)。
Output
對于每組輸入,輸出M個數(shù)的和,每組輸出之間輸出一個空行。
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(黑盒测试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: codeup之复制字符串中的元音字母
- 下一篇: jFinal 使用 SolonMCP 开