桃花潭水深千尺,不及AC送我情~
A+B for Input-Output Practice (VIII)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40850 Accepted Submission(s): 12244
Problem Description
Your task is to calculate the sum of some integers.
Input
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.
Output
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.
Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
Sample Output
10
15
6
解:
#include void main() { int n,i,j,t,sum,a,out[1000],q; sum=0; scanf(“%dn”,&n); for (i=0;i<n;i++) { scanf(“%d”,&j); for (t=0;t<j;t++) { scanf(“%d”,&a); sum=sum+a; out[i]=sum; } sum=0; } q=n-1; for (i=0;i<q;i++) { printf(“%dnn”,out[i]); } printf(“%dn”,out[q]); }
唔,写的比较麻烦。一开始试提示有格式错误.检查了一下,发现是最后面多了一行空行,RT。
当时源代码是这样的:
后来没有很好的解决方法,于是就用了一个笨办法:
于是就变成了这样:
但是HDOJ还是提示格式错误,于是突发奇想在最后的输出那里加了一个n。于是就AC了……
格式错误的原因是最后没有换行……
感觉这个代码好乱,又整理了另外的一个写法:
#include int main() { int a,b,i,j,l[1000],k; scanf(“%d”,&i); getchar(); for(j=1;j<=i;j++) l[j]=0; for(j=1;j<=i;j++) { scanf(“%d”,&a); getchar(); for(k=1;k<=a;k++) { scanf(“%d”,&b); getchar(); l[j]+=b; } } for(j=1;j<=i-1;j++) printf(“%dnn”,l[j]); printf(“%dn”,l[i]); }
至此,ACM steps1 系列的题目全部AC~撒花~
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。