| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 803 人关注过本帖
标题:A+B for Input-Output Practice (VIII)
只看楼主 加入收藏
南方姑娘
Rank: 1
等 级:新手上路
帖 子:21
专家分:5
注 册:2013-8-14
结帖率:37.5%
收藏
已结贴  问题点数:10 回复次数:6 
A+B for Input-Output Practice (VIII)
A+B for Input-Output Practice (VIII)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 74127    Accepted Submission(s): 22958


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<stdio.h>
int main()
{
    int n,m,i,a,sum;
    scanf("%d",&n);
    while(n--)
    {
        while(scanf("%d",&m)!=EOF)
        {
            sum=0;
            for(i=1;i<=m;i++)
            {
                scanf("%d",&a);
                sum+=a;
            }
            printf("%d\n\n",sum);
        }
    }
    return 0;
}
这是我的代码,为什么老是提交上去说的是格式错误,可是我不知道错哪里,求解
搜索更多相关主题的帖子: follow Memory should Java 
2013-08-18 21:36
czz5242199
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:660
专家分:2400
注 册:2011-10-26
收藏
得分:10 
结尾多了一个\n
2013-08-18 22:56
南方姑娘
Rank: 1
等 级:新手上路
帖 子:21
专家分:5
注 册:2013-8-14
收藏
得分:0 
回复 2楼 czz5242199
本来就是要空两行的
2013-08-18 23:30
czz5242199
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:660
专家分:2400
注 册:2011-10-26
收藏
得分:0 
you must note that there is a blank line between outputs.

答案之间需要一个空行,谁说了答案最后也需要一个空行
2013-08-18 23:35
南方姑娘
Rank: 1
等 级:新手上路
帖 子:21
专家分:5
注 册:2013-8-14
收藏
得分:0 
回复 4楼 czz5242199
#include<stdio.h>
int main()
{
    int n,m,i,a,sum;
    scanf("%d",&n);
    while(n--)
    {
        while(scanf("%d",&m)!=EOF)
        {
            sum=0;
            for(i=1;i<=m;i++)
            {
                scanf("%d",&a);
                sum+=a;
            }
            if(n!=0)
                printf("%d\n\n",sum);
            else
                printf("%d\n",sum);
        }
    }
    return 0;
}
改成这样也是格式错误啊
2013-08-19 08:25
czz5242199
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:660
专家分:2400
注 册:2011-10-26
收藏
得分:0 
程序代码:
#include<stdio.h>
int main()
{
    int n,m,i,a,sum;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
            sum=0;
            for(i=1;i<=m;i++)
            {
                scanf("%d",&a);
                sum+=a;
            }
            if(n!=0)
                printf("%d\n\n",sum);
            else
                printf("%d\n",sum);
    }
    return 0;
}
2013-08-19 12:48
南方姑娘
Rank: 1
等 级:新手上路
帖 子:21
专家分:5
注 册:2013-8-14
收藏
得分:0 
回复 6楼 czz5242199
为什么不能用while(scanf("%d",&m)!=EOF)
2013-08-19 21:35
快速回复:A+B for Input-Output Practice (VIII)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019018 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved