A+B for Input-Output Practice

A+B for Input-Output Practice

时间: 1ms        内存:64M

描述:

Your task is to calculate the sum of some integers

输入:

Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line

输出:

For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.

示例输入:

3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3

示例输出:

10

15

6

提示:

参考答案(内存最优[748]):

#include<stdio.h>
int main( )
{
 int n,m,i,k,a,sum=0;
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  scanf("%d",&m);
  for(k=1;k<=m;k++)
  {
    scanf("%d",&a);
    sum+=a;
  }
  printf("%d\n\n",sum);
  sum=0;
 }
  return 0;
}

参考答案(时间最优[0]):

#include<stdio.h>
#include<string.h>
char main()
{int i,length;
 char str[100],t;
 gets(str);
 length=strlen(str);
 for(i=0;i<length/2;i++)
 {t=str[i];
  str[i]=str[length-1-i];
  str[length-1-i]=t;
 }
 puts(str);
 return 0;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注