A+B for Input-Output Practice (VIII)

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

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.

留意between

Sample Input

3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3

Sample Output

10

15

6
  • 第一次提交没有注意到between,OJ返回Presentation Error

between的意思是,输出的数字之间用空行分开,但最后一个输出下面是没有空行

  • 增加判断条件之后第二次提交通过。

Solution

#include <cstdio>
using namespace std;
#define DEBUG 0 //本地调试定义为1, 提交时定义为0 #if DEBUG
#else
#define fp stdin //当DEBUG被定义为0时, fp被替换为stdin
#endif int main() {
#if DEBUG
FILE* fp;
fp = fopen("a.txt", "r"); //a.txt作为文件输入
#endif
int n;
while (fscanf(fp, "%d", &n) != EOF) {
break;
}
int* sum_arr = new int[n];
for (int i = 0; i < n; i++) {
int m;
while (fscanf(fp, "%d", &m) != EOF) {
break;
}
int sum = 0;
for (int j = 0; j < m; j++) {
int add;
while (fscanf(fp, "%d", &add) != EOF) {
break;
}
sum += add;
} sum_arr[i] = sum;
}
for (int i = 0; i < n; i++) {
printf("%d\n", sum_arr[i]);
if (i < n - 1) {
printf("\n");
}
}
delete[] sum_arr;
return 0;
}

如果觉得要反复修改宏定义的DEBUG麻烦,可以把调试语句改为

#ifdef DEBUG
#else
#define fp stdin
#endif int main() {
#ifdef DEBUG
FILE* fp;
fp = fopen("a.txt", "r");
#endif

需要进行本地调试时,使用g++编译选项定义DEBUG

$ g++ 1.1.8.cpp -DDEBUG

运行

$./a

hdoj_Problem1.1.8_A+B for Input-Output Practice (VIII)的更多相关文章

  1. PHP-FPM-failed to ptrace(PEEKDATA) pid 123: Input/output error

    If you're running PHP-FPM you can see these kind of errors in your PHP-FPM logs. $ tail -f php-fpm.l ...

  2. NFS挂载异常 mount.nfs: Input/output error

    [root@localhost ~]# vi /etc/exports #增加/nfs 192.168.10.132(rw,no_root_squash,no_all_squash,async) [r ...

  3. BIOS(Basic Input/Output System)是基本输入输出系统的简称

    BIOS(Basic Input/Output System)是基本输入输出系统的简称 介绍 操作系统老师说,平时面试学生或者毕业答辩的时候他都会问这个问题,可见这个问题对于计算机专业的学生来说是如此 ...

  4. read()、write()返回 Input/output error, Device or resource busy解决

    遇到的问题,通过I2C总线读.写(read.write)fs8816加密芯片,报错如下: read str failed,error= Input/output error! write str fa ...

  5. Angular 个人深究(三)【由Input&Output引起的】

    Angular 个人深究(三)[由Input&Output引起的] 注:最近项目在做别的事情,angular学习停滞了 1.Angular 中 @Input与@Output的使用 //test ...

  6. Docker 在转发端口时的这个错误Error starting userland proxy: mkdir /port/tcp:0.0.0.0:3306:tcp:172.17.0.2:3306: input/output error.

    from:https://www.v2ex.com/amp/t/463719 系统环境是 Windows 10 Pro,Docker 版本 18.03.1-ce,电脑开机之后第一次运行 docker ...

  7. dpdk EAL: Error reading from file descriptor 23: Input/output error

    执行test程序时输出: EAL: Error reading from file descriptor 23: Input/output error 原因: 在虚拟机添加的网卡,dpdk不支持导致的 ...

  8. html5 填表 表单 input output 与表单验证

    1.<output>     Js计算结果 <form oninput="res.value = num1.valueAsNumber*num2.valueAsNumber ...

  9. mount_cd9660:/dev/acd0: Input/output error

    mount -t cd9660 /dev/acd0 /cdrom g_vfs_done():acd0[READ(offset32768, length=204]error =5 mount_cd966 ...

随机推荐

  1. C# 简单粗暴的毫秒转换成 分秒的格式

    C# 简单粗暴的毫秒转换成 分秒的格式 1:code(网络上很多存在拷贝或者存在bug的或者不满足自己的要求) 1 public static string RevertToTime(double m ...

  2. MySQL——字符串类型——char(n) 和 varchar(n)

    MySQL 的 char(n) 和 varchar(n) 括号中 n 代表字符的个数,而非字节个数,这里说的字符不论文字种类,假设一个字段的数据类型被规定为 char(2),则可以在这个字段上插入 ' ...

  3. idea导出jar包及坑

    导出基本步骤 1.打开项目结构,在artifact新建一个jar 2.然后填写主类和依赖 3.这里的坑: 4.查看 5.点击编译输出 6.得到jar包

  4. blender Text on Curve Text on Sphere

    Text on Curve Shift + A 添加一个 BezierCurve Shift + A 添加一个 Text,Tab 编辑,再次 Tab 退回 Object Mode 选中 Text,Ad ...

  5. css文本溢出省略号大总结,如你所愿

    一行: white-space: nowrap; text-overflow: ellipsis; overflow: hidden; word-break: break-all; 两行: width ...

  6. Django——数据库连接配置

    配置settings.py : DATABASES = { 'default': { #default表示默认,也可以指定app 'ENGINE': 'django.db.backends.mysql ...

  7. hash类型数据的操作指令

    1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.

  8. LeetCode刷题模板(1):《我要打10个》之二分法

    Author       :  叨陪鲤 Email         : vip_13031075266@163.com Date          : 2021.01.23 Copyright : 未 ...

  9. [源码解析] 深度学习流水线并行 PipeDream(6)--- 1F1B策略

    [源码解析] 深度学习流水线并行 PipeDream(6)--- 1F1B策略 目录 [源码解析] 深度学习流水线并行 PipeDream(6)--- 1F1B策略 0x00 摘要 0x01 流水线比 ...

  10. 496. 下一个更大元素 I

    496. 下一个更大元素 I 给定两个 没有重复元素 的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集.找到 nums1 中每个元素在 nums2 中的下一个比其大的值. ...