【ACM】【杭电】用C语言实现1096

1095如题

杭电1096

题目解析:


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.

大致意思是:输入一个N表示进行多少次求和,每一行第一个数表示对接下来的M个整数求和


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.

大概意思是:将每一个和进行空行输出,即每个结果之间空一行


逐步实现代码

注意

这里需要注意的是,在最后一次输出之后不需要再进行空行处理

#include<stdio.h>
int main()
{
    int m, n, sum, i;				//初始化数值,可以留到最后再定义
    while(scanf("%d",&n)!=EOF)		//首先利用 while 获取求和次数n
    {
        while(n--)					//用while循环开始求和
        {
            sum = 0;				//初始化 sum,因为要多次求和
            scanf("%d",&m);			//获得M即求和数个数
            while(m--)				//m 个数求和
            {
                scanf("%d",&i);		//获取元素
                sum += i;			//求和
            }
            if(n == 0)				//两个输出行之间进行空行处理,这里需要注意的是
                printf("%d\n",sum); //在最后一次输出之后不需要再进行空行处理,所以用到了if语句
            else
                printf("%d\n\n",sum);
        }
    }
}

这一题将1093进行了变换,在输出方面做了一点改动

其中while(scanf(“%d%d“,&a,&b)!=EOF)用法详见ACM-while(scanf(“%d%d“,&a,&b)!=EOF)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值