暑假训练(二) 等待的题目

来源:互联网 发布:ug10.0车削编程 编辑:程序博客网 时间:2024/05/17 08:44

有几个题目显示的是等待,不知道对不对,不过已经做了,就先传上来。



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 23 40 0

Sample Output

37


一:源代码

#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 45 1 2 3 4 50 

Sample Output

1015



一:源代码

#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 34 5 6

Sample Output

615



这个题目根据要求,每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

22 1 25 3 4 6 9 3

Sample Output

29


一:源代码

#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;
}


二:结果截图


原创粉丝点击