2020-12-16HDOJ-ACMsteps笔记
2024-10-21 06:32:17
1.1.5
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 with one line of output for each line in input.
Sample Input
2
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
#include <stdio.h>
int main()
{
int n,i,a,new,sum=0;
scanf("%d",&n);
i=0;
while (~scanf("%d",&a)&&i<n)
{
while(a--)
{
scanf("%d",&new);
sum+=new;
}
printf("%d\n",sum);
i++;
sum=0;/*一定要把sum重新置零,不然会
带着上一行输入的sum继续做加法*/
}
return 0;
}
也改了许多次才通过.需要特别注意注释处的细节
还有,学到方法while(a–)来代替计数器.
最新文章
- 基于XML的AOP配置-转
- Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- AIDL
- [New Portal]Windows Azure Virtual Machine (10) 自定义Windows Azure Virtual Machine模板
- Spring中@Component注解,@Controller注解详解
- JS常用各种正则表达式
- hdu 1829-A Bug&#39;s LIfe(简单带权并查集)
- 文件夹同步/备份软件推荐 (SyncToy/FreeFileSync/Compare Advance/GoodSync/Allway Sync/Compare Advance)
- Python 文件操作模块 shutil 详解
- python 遍历字典
- 关于bootstrap弹出二级对话框的使用
- php获胜的算法的概率,它可用于刮,大转盘等彩票的算法
- javascript遍历select下拉框判断其中值是否与指定值相等
- hdu4284之字典树
- <;C++Primer>;第四版 阅读笔记 第一部分 “基本语言”
- JStorm与Storm源码分析(五)--SpoutOutputCollector与代理模式
- Java I/O 从0到1 - 第Ⅰ滴血 File
- 优雅地实现CSS Animation delay
- win10 vscode使用 智能提示
- 发布core到linux
- CodeForces1073E 数位dp+状压dp