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 ...
随机推荐
- Win10 pip install augimg 报 OSError: [WinError 126] 找不到指定的模块,解决办法
第一种Win10下python成功安装augimg的方法: 下载Shapely,地址https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely,选择对应版本 ...
- Three.js 中 相机的常用参数含义
Three.js 中相机常用的参数有up.position和lookAt. position是指相机所在的位置,将人头比作相机的话,那么position就是人头的中心的位置: up类似于人的脖子可以调 ...
- MySQL数据库迁移之data目录
其实迁移数据库,一般用sql文件就行,把A服务器数据库的表结构和数据等等导出,然后导入到B服务器数据库, 但是这次数据文件过大,大约有40个G,使用命令行导入,效果不是很好,经常在执行过程中报错.卡死 ...
- msyql redo log和binlog
更新语句执行流程 下面是这个表的创建语句,这个表有一个主键 ID 和一个整型字段 c: create table T(ID int primary key, c int); 如果要将 ID=2 这一行 ...
- Mybatis(二)——全局配置文件
一.在正文上方直接添加目录. 1.二级标题***申请开通js权限 2.添加js脚本到页脚Html代码 数组:采用一段连续的存储单元来"存储"数据.对于"指定下标" ...
- MySQL——MySQL安装
1.rpm yum安装:安装方便.速度快.无法定制 2.二进制安装:解压即可使用,不能定制功能 3.编译安装: 可定制.安装慢: MySQL5.5之前:./configure make make in ...
- harbor高可用集群搭建
高可用harbor集群搭建 一.安装部署 1.节点角色 角色 数量 名称 备注 harbor主节点 2 harbor-1 harbor-2 双主模式 haproxy 2 HA-1 HA-2 需要通过k ...
- Python常见问题 - python3 requests库提示警告InsecureRequestWarning的问题
当使用 requests 库发送请求时报了以下警告 D:\python3.6\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequ ...
- sed中传递变量进行替换
sed命令中传递变量 例如:修改配置文件某一个变量的值 配置文件如下: toney@ubantu:/mnt/hgfs/em嵌入式学习记录/shell/shell脚本常见用法$ cat common_u ...
- DP 习题
一.简单基础dp 这类dp主要是一些状态比较容易表示,转移方程比较好想,问题比较基本常见的.主要包括递推.背包.LIS(最长递增序列),LCS(最长公共子序列),下面针对这几种类型,推荐一下比较好的学 ...