ACM Steps之一(Section One)

這篇博文呢,我們給大家提供杭電上面的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&sectionid=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;
}



 


發佈了25 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章