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 ...
随机推荐
- Seq2Seq sequence-to-sequence模型 简介
Sequence-to-sequence (seq2seq) 模型. 突破了传统的固定大小输入问题框架 开创了将DNN运用于翻译.聊天(问答)这类序列型任务的先河 并且在各主流语言之间的相互翻译,和语 ...
- Python3-sqlalchemy-orm
1 #-*-coding:utf-8-*- 2 #__author__ = "logan.xu" 3 4 5 import sqlalchemy 6 from sqlalchemy ...
- css 文字超出俩行省略号显示
.center-titles{ overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: ...
- 如何实现LRU缓存?
面试官:来了,老弟,LRU缓存实现一下? 我:直接LinkedHashMap就好了. 面试官:不要用现有的实现,自己实现一个. 我:..... 面试官:回去等消息吧.... 大家好,我是程序员学长,今 ...
- MySQL——优化
MySQL数据库优化: 1.优化角度 安全: 数据可持续性 性能: 数据的高性能访问 2.优化范围(优化顺序---->) (1)存储.主机和操作系统: 主机架构稳定性 I/O规划及配置 swap ...
- TDSQL(MySQL版)之DB组件升级
随着数据库产品的更新迭代,修复bug等等,产品避免不了会出现升级的需求.TDSQL(MysqL版)也会有这方面的需求.接下来我就说说如何对现有TDSQL(MySQL版)集群组件进行升级,而不影响业务. ...
- Mysql常用sql语句(4)- distinct 去重数据
测试必备的Mysql常用sql语句系列 https://www.cnblogs.com/poloyy/category/1683347.html 前言 我们使用select进行数据查询时是会返回所有匹 ...
- freeswitch python模块
概述 freeswitch支持多种语言的业务开发,包括C/C++,java,python,js,lua,Golang等等.freeswitch在使用python做业务开发时,有俩种接入方式,一种是ES ...
- springboot整合jsp报错
今天在学springboot整合jsp时遇到了一个问题,虽然jsp不被spring官方推荐使用,但抱着学习的心态还是想解决一下这个问题.在写好了需要pom文件之后,访问网站得到了500的错误提示,后台 ...
- JS验证监听输入银行卡号
$("#AccountNum").keydown(function(e) { if(!isNaN(this.value.replace(/[ ]/g,""))) ...