首页
学习
活动
专区
工具
TVP
发布

Contest100000574 – 《算法笔记》2.10小节——C/C++快速入门->黑盒测试

http://codeup.cn/contest.php?cid=100000574

Problem A: A+B 输入输出练习I

Time Limit: 1 Sec Memory Limit: 32 MB

Submit: 5010 Solved: 2613

Description

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

Input

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

Output

对于输入的每对a和b,你需要依次输出a、b的和。

如对于输入中的第二对a和b,在输出中它们的和应该也在第二行。

Sample Input

1 5

10 20

Sample Output

6

30

代码(C语言)

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

Problem B: A+B 输入输出练习II

Time Limit: 1 Sec Memory Limit: 32 MB

Submit: 2870 Solved: 2094

Description

你的任务是计算a+b。

Input

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

Output

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

如第二对a和b,对应的和也输出在第二行。

Sample Input

2
1 5
10 20

Sample Output

6
30

代码(C语言)

#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;
}

Problem C: A+B 输入输出练习III

Time Limit: 1 Sec Memory Limit: 32 MB

Submit: 2567 Solved: 1971

Description

你的任务是计算a+b。

Input

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

Output

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

如第二对a和b,他们的和也输出在第二行。

Sample Input

1 5
10 20
0 0

Sample Output

6
30

代码(C语言)

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

Problem D: A+B 输入输出练习IV

Time Limit: 1 Sec Memory Limit: 32 MB

Submit: 3325 Solved: 1822

Description

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

Input

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

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

Output

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

Sample Input

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

Sample Output

10
15

代码(C语言)

代码1

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

代码2(C语言)

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

Problem E: A+B 输入输出练习V

Time Limit: 1 Sec Memory Limit: 32 MB

Submit: 2263 Solved: 1673

Description

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

Input

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

Output

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

Sample Input

2

4 1 2 3 4
5 1 2 3 4 5

Sample Output

10
15

代码(C语言)

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

Problem F: A+B 输入输出练习VI

Time Limit: 1 Sec Memory Limit: 32 MB

Submit: 2381 Solved: 1566

Description

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

Input

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

Output

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

Sample Input

4 1 2 3 4
5 1 2 3 4 5

Sample Output

10
15

注意:和问题IV没什么大区别就是少了个0的判断条件,第一次提交超时,因为忘了!=EOF这个条件。

一定要记住:没说明有多少数据要输入的时候,就用EOF判断!

代码(C语言)

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

    return 0;
 }

Problem G: A+B 输入输出练习VII

Time Limit: 1 Sec Memory Limit: 32 MB

Submit: 2002 Solved: 1551

Description

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

Input

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

Output

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

Sample Input

1 5
10 20

Sample Output

6

30

代码(C语言)

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

Problem H: A+B 输入输出练习VIII

Time Limit: 1 Sec Memory Limit: 32 MB

Submit: 2134 Solved: 1602

Description

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

Input

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

Output

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

Sample Input

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

Sample Output

10

15

6

代码(C语言)

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

鸣谢

dulongxiang(https://blog.csdn.net/dulongxiang/article/details/81556999)

(https://blog.csdn.net/dulongxiang/article/details/81557456)

(https://blog.csdn.net/dulongxiang/article/details/81557762)

szu9898(https://blog.csdn.net/weixin_42127158/article/details/80888624)

(https://blog.csdn.net/weixin_42127158/article/details/80888508)

版权所有:可定博客 © WNAG.COM.CN

本文标题:《Contest100000574 – 《算法笔记》2.10小节——C/C++快速入门->黑盒测试》

本文链接:https://cloud.tencent.com/developer/article/1616887

特别声明:除特别标注,本站文章均为原创,本站文章原则上禁止转载,如确实要转载,请电联:wangyeuuu@qq.com,尊重他人劳动成果,谢过~

下一篇
举报
领券