techiall / Blog

🍋 [My Blog] See discussions
https://github.com/techiall/Blog/discussions
MIT License
8 stars 1 forks source link

输入输出练习 #2

Open techiall opened 6 years ago

techiall commented 6 years ago

题库链接

http://acm.two.moe:808/JudgeOnline/

Linux 内核代码风格(供参考

https://www.kernel.org/doc/html/v4.13/translations/zh_CN/coding-style.html

1092: 输入输出练习之A+B(1)

1092: 输入输出练习之A+B(1)
题目描述
计算a+b

输入
若干组测试数据,每组测试数据占一行,包含2个整数a和b,空格隔开。

输出
对于每组测试数据,输出占一行,结果为a+b的和。

样例输入
1 5
10 20
样例输出
6
30

参考代码

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

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

1093: 输入输出练习之A+B(2)

1093: 输入输出练习之A+B(2)
题目描述
计算a+b

输入
第一行为一个整数n,接下来有n行。每行包含2个整数a和b,空格隔开。

输出
对于每对a和b,计算它们的和,并占一行输出。

样例输入
2
1 5
10 20
样例输出
6
30

参考代码

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

1094: 输入输出练习之A+B(3)

1094: 输入输出练习之A+B(3)
题目描述
计算a+b

输入
输入包含多组测试用例。每组用例占一行,包含2个整数a和b。最后一组用例为0 0,表示输入结束,该用例不需要处理。

输出
对于每组输入用例,输入a+b的和,占一行。

样例输入
1 5
10 20
0 0
样例输出
6
30

参考代码

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

//#include <stdio.h>
//int main(void)
//{
//#ifdef _DEBUG
//  freopen("in.txt", "r", stdin);
//  //freopen("out.txt", "w", stdout);
//#endif // _DEBUG
//  int a, b;
//  while (~scanf("%d %d", &a, &b) && (a || b)) {
//      printf("%d\n", a + b);
//  }
//  return 0;
//}

1095: 输入输出练习之A+B(4)

1095: 输入输出练习之A+B(4)
题目描述
计算整数的和。

输入
输入包含多组测试用例。每组用例占一行,每行第一个整数为n,接下来有n个整数。以0开头的用例表示输入结束,该组用例不需要处理。

输出
对于每组测试用例,计算该用例中n个整数的和,占一行输出。

样例输入
4 1 2 3 4
5 1 2 3 4 5
0 
样例输出
10
15

参考代码

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

1096: 输入输出练习之A+B(5)

1096: 输入输出练习之A+B(5)
题目描述
计算整数的和。

输入
第一行为一个整数n,接下来有n行。每一行第一个整数为m,该行接下来有m个整数。

输出
对于每组测试用例,计算m个整数的和,输出占一行。

样例输入
2
4 1 2 3 4
5 1 2 3 4 5
样例输出
10
15

参考代码

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

1097: 输入输出练习之A+B(6)

1097: 输入输出练习之A+B(6)
题目描述
计算整数的和。

输入
输入包含多组测试用例,每组用例占一行。每组用例第一个整数为n,接下来该行有n个整数。

输出
对于每组用例,计算n个整数的和,占一行输出。

样例输入
4 1 2 3 4
5 1 2 3 4 5
样例输出
10
15

参考代码

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

1098: 输入输出练习之A+B(7)

1098: 输入输出练习之A+B(7)
题目描述
计算a+b

输入
输入包含多组数据,每组占一行。每一行有2个整数a和b,空格隔开。

输出
对于每组数据,计算a+b的和,然后输出一个空行。

样例输入
1 5
10 20
样例输出
6

30

参考代码

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

1099: 输入输出练习之A+B(8)

1099: 输入输出练习之A+B(8)
题目描述
计算整数的和。

输入
输入第一行为一个整数n,接下来有n行。每一行开头有一个整数m,接下来有m个整数。

输出
对于每组数据,输出m个整数的和。同时每组输出之间有一个空行。

样例输入
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
样例输出
10

15

6

参考代码

#include <stdio.h>
int main(void)
{
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif // _DEBUG

    int n;
    scanf("%d", &n);
    int falg = 0;
    while (n--) {
        int t;
        scanf("%d", &t);
        int x;
        int sum = 0;
        for (int i = 0; i < t; i++) {
            scanf("%d", &x);
            sum += x;
        }
        printf("%d%s", sum, n == 0 ? "" : "\n\n");
    }
    return 0;
}