1. 程式人生 > >暑假訓練(二) 等待的題目

暑假訓練(二) 等待的題目

有幾個題目顯示的是等待,不知道對不對,不過已經做了,就先傳上來。

1205  Problem P:多組測試資料(a+b)III

Description

對於多組測試資料,還有一些是沒有明確告訴你多少組,但會告訴你輸入什麼樣的資料就結束,如每組輸入2個整數,但如果輸入的是0 0就結束,這類題目的處理方法是 


int main() 



int a,b; 

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



//輸入的是0 0就結束 

if(a==0 && b==0) 

break; 

...//這裡是輸入不是結束資料的處理 



}

Input

多組測試資料,每組1行,輸入2個整數 
輸入2個0 0的時候結束且該組資料不需要處理

Output

對於每組測試資料輸出一行,內容為2個數的和

Sample Input

1 2
3 4
0 0

Sample Output

3
7

一:原始碼

#include<stdio.h>
int main()
{
int a,b; 
    while(scanf("%d%d",&a,&b)!=EOF) 

     if(a==0 && b==0) 
        break; 
     else 
      printf("%d\n",a+b);
    }  
    return 0;
}

二:結果截圖


1206  Problem Q:多組測試資料(求和)IV

Description

還有一些輸入是以上幾種情況的組合,具體根據題目對前面幾種情況進行組合 
比如題目要求是多組測試資料 
每組測試資料首先輸入一個整數n(如果n=0就表示結束) 然後再輸入n個整數 
這類題目輸入格式如下: 


int main() 



int n,i; 

while(scanf("%d",&n)!=EOF && n!=0) 



for(i=1;i<=n;i++) 



....//每次輸入一個數,共迴圈n次,需要的時候做其他處理 







}

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

一:原始碼

#include<stdio.h>
int main() 

    int n,i,s,a[1000]; 
    while(scanf("%d",&n)!=EOF&&n!=0) 

s=0;
       for(i=1;i<=n;i++) 
  { 
           scanf("%d",&a[i]);
  s=s+a[i];
  } 
  printf("%d\n",s);

return 0;
}



二:結果截圖











1207  Problem R:多組測試資料輸出

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


這個題目根據要求,每2組測試資料之間有1個空行,題目給的提示是第一種,但是第二種也滿足,不知道哪種可以通過,就先都傳上來看看。

第一種

一:原始碼

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

二:結果截圖


第二種

一:原始碼

#include<stdio.h>
int main() 

     int a,b,c,s; 
     while(scanf("%d%d%d",&a,&b,&c)!=EOF) 
{
        s=a+b+c; 
        printf("%d\n\n",s);

   return 0;
}

二:結果截圖


1208  Problem S:求最大值

Description

輸入一些整數,求最大值

Input

多組測試資料 
首先輸入1個整數n表示測試組數 
然後每行首先輸入1個整數m,再輸入m個整數

Output

對於每組測試資料輸出1行,內容為m個整數的最大值

Sample Input

2
2 1 2
5 3 4 6 9 3

Sample Output

2
9

一:原始碼

#include<stdio.h>
int main() 

     int n,max,i,q,j,a[10000]; 
     while(scanf("%d",&n)!=EOF) 
{
        for(i=0;i<n;i++)
{
scanf("%d",&q);
for(j=0;j<q;j++)
   scanf("%d",&a[j]);
       max=a[0];
        for(j=0;j<q;j++)
{
      if(max<a[j])max=a[j];
}
     printf("%d\n",max);
}

   return 0;
}

二:結果截圖