| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 531 人关注过本帖
标题:ACM的一道简单题
只看楼主 加入收藏
kolnick
Rank: 2
等 级:论坛游民
帖 子:24
专家分:13
注 册:2009-6-24
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
ACM的一道简单题
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"
main()
{
int n,m,sum=0,i,j,k,l=0;
 scanf("%d",&n);
 for(i=1;i<=n;i++)
   {
    sum=0;
     scanf("%d",&m);
     for(j=1;j<=m;j++)
     {
      scanf("%d",&k);
      sum+=k;
     }

      printf("%d\n\n",sum);
   }
}
问题就是如何让最后一行不输出空行
搜索更多相关主题的帖子: ACM 
2010-11-08 11:16
NoSoul
Rank: 9Rank: 9Rank: 9
来 自:沈阳化工大学
等 级:蜘蛛侠
帖 子:283
专家分:1010
注 册:2009-6-6
收藏
得分:10 
#include <stdio.h>
int main()
{
    int T,n,x,sum,f;
    scanf("%d",&T);
    f=0;
    while(T--)
    {
        if(f)
            printf("\n");
        scanf("%d",&n);
        sum=0;
        while(n--)
        {
            scanf("%d",&x);
            sum+=x;
        }
        printf("%d\n",sum);
        f=1;
    }
    return 0;
}

我想伸手拉近點,竟觸不到那邊,就欠一點點,但這一點點...卻好遠
2010-11-08 11:29
快速回复:ACM的一道简单题
数据加载中...
 
   



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

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