「Solution」A+B Problem N-VIII

虹棠包
2023-12-12 / 0 评论 / 29 阅读 /
温馨提示:
本文最后更新于2024年01月02日,已超过490天没有更新,若内容或图片失效,请留言反馈。

Creation:2023/12/10 14:31:38

这章的题都挺简单,是对输入输出的练习,直接附答案了。但也欢迎大家评论区留言和讨论~

A + B Problem

Problem ID:1000
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Calculate A + B.

Input

Each line will contain two integers A and B. Process to end of file.

Output

For each case, output A + B in one line.

Sample Input

1 1

Sample Output

2

Author

HDOJ

Solution

注意,这里题目要求是Process to end of file.,故要用EOF判断输入的结束。

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

A+B for Input-Output Practice (I)

Problem ID:1089
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.

Input

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20

Sample Output

6
30

Author

lcy

Solution

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

A+B for Input-Output Practice (II)

Problem ID:1090
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Your task is to Calculate a + b.

Input

Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

2
1 5
10 20

Sample Output

6
30

Author

lcy

Solution

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

A+B for Input-Output Practice (III)

Problem ID:1091
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Your task is to Calculate a + b.

Input

Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20
0 0

Sample Output

6
30

Author

lcy

Solution

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

A+B for Input-Output Practice (IV)

Problem ID:1092
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Your task is to Calculate the sum of some integers.

Input

Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.

Output

For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input

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

Sample Output

10
15

Author

lcy

Solution

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

A+B for Input-Output Practice (V)

Problem ID:1093
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Your task is to calculate the sum of some integers.

Input

Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output

For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input

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

Sample Output

10
15

Author

lcy

Solution

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

A+B for Input-Output Practice (VI)

Problem ID:1094
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Your task is to calculate the sum of some integers.

Input

Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.

Output

For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.

Sample Input

4 1 2 3 4
5 1 2 3 4 5

Sample Output

10
15

Author

lcy

Solution

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

A+B for Input-Output Practice (VII)

Problem ID:1095
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Your task is to Calculate a + b.

Input

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.

Sample Input

1 5
10 20

Sample Output

6

30

Author

lcy

Solution

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

A+B for Input-Output Practice (VIII)

Problem ID:1096
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Your task is to calculate the sum of some integers.

Input

Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output

For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.

Sample Input

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

Sample Output

10

15

6

Author

lcy

Solution

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

Sum Problem

Problem ID:1001
Time Limit: 1000/500 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description

Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.

Input

The input will consist of a series of integers n, one integer per line.

Output

For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.

Sample Input

1
100

Sample Output

1

5050

Author

DOOM III

Solution

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

评论 (0)

取消