這篇博文呢,我們給大家提供杭電上面的ACM Steps模塊Section One的題解代碼。這些題都是最基本的題,可以幫助你熟悉杭電上題目的格式,下面我們來看看吧~~
A+B for Input-Output Practice (II) |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
Total Submission(s): 16378 Accepted Submission(s): 10924 |
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,n;
scanf("%d",&n);
while(n--){
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
return 0;
}
這道題好水的吧,那就來下一站吧,下面就不一一粘貼題目了,大家可以直接去杭電上看
http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=1
以下是第三題的代碼
#include<stdio.h>
int main(){
int a,b;
while(scanf("%d%d",&a,&b)){
if(a==0&&b==0)
break;
else
printf("%d\n",a+b);
}
return 0;
}
第四題
#include<stdio.h>
int main(){
int n,i,s,k;
while(scanf("%d",&n)!=EOF)
{
s=0;
if(n==0) break;
else
{
for(i=0;i<n;i++)
{
scanf("%d",&k);
s=s+k;
}
printf("%d\n",s);
}
}
return 0;}
第五題
#include<stdio.h>
int main(){
int n,i,s,k,c,j;
scanf("%d",&c);
for(j=0;j<c;j++)
{
scanf("%d",&n);
{
s=0;
{
for(i=0;i<n;i++)
{
scanf("%d",&k);
s=s+k;
}
printf("%d\n",s);
}
}
}
return 0;
}