hdoj_Problem1.1.8_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)
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)的更多相关文章
- 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 ...
- 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 ...
- BIOS(Basic Input/Output System)是基本输入输出系统的简称
BIOS(Basic Input/Output System)是基本输入输出系统的简称 介绍 操作系统老师说,平时面试学生或者毕业答辩的时候他都会问这个问题,可见这个问题对于计算机专业的学生来说是如此 ...
- read()、write()返回 Input/output error, Device or resource busy解决
遇到的问题,通过I2C总线读.写(read.write)fs8816加密芯片,报错如下: read str failed,error= Input/output error! write str fa ...
- Angular 个人深究(三)【由Input&Output引起的】
Angular 个人深究(三)[由Input&Output引起的] 注:最近项目在做别的事情,angular学习停滞了 1.Angular 中 @Input与@Output的使用 //test ...
- 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 ...
- dpdk EAL: Error reading from file descriptor 23: Input/output error
执行test程序时输出: EAL: Error reading from file descriptor 23: Input/output error 原因: 在虚拟机添加的网卡,dpdk不支持导致的 ...
- html5 填表 表单 input output 与表单验证
1.<output> Js计算结果 <form oninput="res.value = num1.valueAsNumber*num2.valueAsNumber ...
- 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 ...
随机推荐
- Mysql索引最佳实践笔记0524
#mysql5.7 innodb默认存储引擎 一.关于索引二.最佳实践三.避坑实践 一.关于索引 1.索引的作用 -提高查询效率 -数据分组.排序 -避免回表查询 -优化聚集查询 -用于多表join关 ...
- Android手机 自动批量发朋友圈
做了各种对比之后,还是这个微商工具最好用
- 小程序 读取照片 EXIF 元信息
安装 exif.js npm install exif-js --save UI <button type="primary" @click="onExif&quo ...
- ELK+kafka+filebeat搭建生产ELFK集群
文章原文 ELK 架构介绍 集群服务版本 服务 版本 java 1.8.0_221 elasticsearch 7.10.1 filebeat 7.10.1 kibana 7.10.1 logstas ...
- 启动线程组报错:Error occurred starting thread group :test_1, error message:Invalid duration 0 set in Thread Group:test_1, see log file for more details
线程组基础信息都已经配置好,启动时报错,如下图: 排查原因:勾选了线程组调度器,并未设置参数 解决方案:取消勾选或者设置参数
- 中心对称数 II
中心对称数 II 1.题目描述 中心对称数是指一个数字在旋转了 180 度之后看起来依旧相同的数字(或者上下颠倒地看). 找到所有长度为 n 的中心对称数. 示例 : 输入: n = 2 输出: [& ...
- c++ undefined reference
记录一次c++编程时发现的问题 报错 undefined reference undefined reference to `Student::~Student()' 下面还有类似的好几行,翻译过来就 ...
- 在PHP中使用SPL库中的对象方法进行XML与数组的转换
虽说现在很多的服务提供商都会提供 JSON 接口供我们使用,但是,还是有不少的服务依然必须使用 XML 作为接口格式,这就需要我们来对 XML 格式的数据进行解析转换.而 PHP 中并没有像 json ...
- 还不知道PHP有闭包?那你真OUT了
做过一段时间的Web开发,我们都知道或者了解JavaScript中有个非常强大的语法,那就是闭包.其实,在PHP中也早就有了闭包函数的功能.早在5.3版本的PHP中,闭包函数就已经出现了.到了7以及后 ...
- Java基础系列(37)- 数组下标越界及小结
数组的四个基本特点 其长度是确定的,数组一旦被创建,它的大小就是不可以改变的 其元素必须是相同类型,不允许出现混合类型 数组中的元素可以是任何数据类型,包括基本类型和引用类型 数组变量属于引用类型,数 ...