1137: 零起點學算法44——多組測試數據輸出II
Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 1513 Accepted: 1007
[Submit][Status][Web Board]
Description
對於每一組數據輸入后先處理然后輸出結果,再輸入第2組數據,
輸出數據之間要求有一個空行
int main()
{
int a,b,c,t=0;
while(scanf("%d%d",&a,&b)!=EOF)
{
c=a+b;
if( t>0) printf("\n");
printf("%d\n",c);//注意后面的\n
t++;
}
}
Input
多組測試數據,每組輸入3個整數
Output
對於每組測試數據,輸出1行,內容為輸入的3個數的和,每2組測試數據之間有1個空行
Sample Input 
1 2 3
4 5 6
Sample Output
6
15
Source
1 #include<stdio.h> 2 int main(){ 3 int a,b,c,t=0; 4 while(scanf("%d%d%d",&a,&b,&c)!=EOF){ 5 if(t>0) printf("\n"); 6 printf("%d\n",a+b+c); 7 t++; 8 } 9 return 0; 10 }
//別小看這題簡單。 記住 最后一組數據后面只有一個換行 沒有兩個, 所以應當是先if判斷再輸出,而不是先輸出后判斷。 雖然最后結果一樣,但是最后的換行不一樣!!!