ACM总结之 A+B problem 总结

nyoj    A+B problem

时间限制:3000 ms  |  内存限制:65535 KB
难度:0
 
描述
此题为练手用题,请大家计算一下a+b的值
 
输入
输入两个数,a,b
输出
输出a+b的值
样例输入
2 3样例输出
5

 

代码:
#include <stdio.h>

int main()

 { int a,b;

while(scanf("%d%d",&a,&b)!=EOF);
printf("%d",a+b);

return 0;
}   

 

hdu1000

A + B ProblemTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)


Total Submission(s): 317452    Accepted Submission(s): 92274

 

 

 


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
代码:


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

 

 

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

Total Submission(s): 221055    Accepted Submission(s): 54049

 

 

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
 
代码:
#include<stdio.h>
int main()
{int a,b,sum=0;
while(scanf("%d",&b)!=EOF)
{sum=0;
for(a=1;a<=b;a++)
{
sum=sum+a;
}

printf("%d\n\n",sum);
}
return 0;
}
hdu 1089
A+B for Input-Output Practice (I)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 62478    Accepted Submission(s): 35144


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
 
代码:
#include <stdio.h>
int main()
{int a,b;
    while(scanf("%d %d",&a,&b)!=EOF)
    printf("%d\n",a+b);
    return 0;
}
 
hdu 1090

A+B for Input-Output Practice (II)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 47298    Accepted Submission(s): 31464

 

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
 
Recommend
JGShining
 
代码:
#include <stdio.h>
int main()
{int a,b,c,m=1;
    scanf("%d",&c);
    while(scanf("%d %d",&a,&b)!=EOF)
    if(m<=c)
    {
    printf("%d\n",a+b);
    m++;
    }
    return 0;
}

hdu 1091
A+B for Input-Output Practice (III)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 56525    Accepted Submission(s): 29033

 

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
 


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

hdu 1092
A+B for Input-Output Practice (IV)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50203    Accepted Submission(s): 26934

 

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
 


Recommend
JGShining
代码:
#include "stdio.h"
int a[100];
int main()
{int i,n;
    int sum(int x);
    while(scanf("%d",&n)&&n!=0)
    {for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    printf("%d\n",sum(n));
    }
    return 0;
}
int sum(int x)
{int c=0,y;
    for(y=0;y<x;y++)
    c=c+a[y];
    return (c);
}


hdu 1093
A+B for Input-Output Practice (V)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36626    Accepted Submission(s): 24922

 

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

4 1 2 3 4
5 1 2 3 4 5
 


Sample Output
10
15
 


Author
lcy
代码:
#include "stdio.h"
#define P 1000
int a[P];
int main()
{int i,n,m,s=0;
scanf("%d",&n);
while(n--)
{scanf("%d",&m);
for(i=0;i<m;i++)
{scanf("%d",&a[i]);
s=s+a[i];
}
printf("%d\n",s);
s=0;
}
return 0;
}

 一般来说,A+B problems 只是简单题,练习基本的输入输出而已,一般有三种格式:

一: 输入不说明有多少个Input Block,以EOF为结束标志

#include <stdio.h>

 int main()

 {
    int a,b;
    while(scanf("%d %d",&a, &b) != EOF)      printf("%d\n",a+b);
 }
 二: 输入一开始就会说有N个Input Block,下面接着是N个Input Block。
 
#include <stdio.h>
 int main()
 {
    int n,i,a,b;
 scanf("%d",&n);
for(i=0;i<n;i++)
{
   scanf("%d %d",&a, &b);
    printf("%d\n",a+b);
 }
 }
或者是:
#incldue "stdio.h"
int main()
{int a,b,n;
scanf("%d",&n);
while(n--)
{scanf("%d%d",&a,&b);
{.........
}
}
}
三: 输入不说明有多少个Input Block,但以某个特殊输入为结束标志。
以输入0 0 为结束标志为例如下:
 
#include <stdio.h>
 int main()
 {
int a,b;
while(scanf("%d %d",&a, &b) &&(a!=0 || b!=0))
    printf("%d\n",a+b);
 }
 

 

 

  

转载于:https://www.cnblogs.com/songmingtao/p/3217180.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值