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 ...
随机推荐
- js调试之firbug
说下几种方法吧: 1.用alert 这个最最直观 把你想要的内容弹出来给你看,但是要看哪里 就要在哪里加,比较麻烦 2.用firefox 或者chrome浏览器 里面有debug工具的 3.如果想用i ...
- 1,Spark参数调优
Spark调优 目录 Spark调优 一.代码规范 1.1 避免创建重复RDD 1.2 尽量复用同一个RDD 1.3 多次使用的RDD要持久化 1.4 使用高性能算子 1.5 好习惯 二.参数调优 资 ...
- linux系统配置本地yum源
1. 前言 学习Linux系统需要大量的实验,而每次安装系统和准备安装系统后的基础配置比较耗时费力.如果在生产环境中,遇到内网(无法访问互联网)情况下,就需要利用挂载的ISO文件内的Packages中 ...
- MySQL——主从复制
---- 高可用 ---- 辅助备份 ---- 分担负载 复制是MySQL的一项功能,允许服务器将更改从一个实例复制到另一个实例. --主服务器将所有数据和结构更改记录到二进制日志中. --从属服务器 ...
- MySQL——MySQL多实例
一台服务器上运行多个MySQL服务,不同的业务 多实例思路: 1. 多套配置文件 2. 多套数据 3. 多个socket 4. 多个端口 5. 多个日志文件 6. 多个启动程序
- Appium问题解决方案(2)- AttributeError:module 'appium.webdriver' has no attribute 'Remote'
背景 运行脚本的时候,就直接报这个错误了,然后去看了下 appium.webdriver 库 结果发现啥都没有,就知道有问题了,然后一步步排查 步骤一 检查Appium-Python-Client 和 ...
- Linux的基础命令(一)
目录: 一.Linux系统基础 1.shell 2. Linux命令的分类 二.Linux命令行 1.Linux命令行提示符 2.Linux通用命令行使用格式 3.Lin ...
- 机器学习——主成分分析(PCA)
1 前言 PCA(Principal Component Analysis)是一种常用的无监督学习方法,是一种常用的数据分析方法. PCA 通过利用 正交变换 把由 线性相关变量 表示的观测数据转换为 ...
- Django学习day01随堂笔记
每日测验 """ 每日测验 1.你所知道的前端框架和实用插件有哪些,他们各有什么特点 2.使用bootstrap需要注意什么,常用的bootstrap样式有哪些 &quo ...
- 【PHP数据结构】在学数据结构和算法的时候我们究竟学的是啥?
一说到数据结构与算法,大家都会避之不及.这本来是一门专业基础课,但是大部分人都并没有学好,更不用说我这种半路出家的码农了.说实话,还是很羡慕科班出身的程序员,因为你们在日常工作或者面试中,只需要复习一 ...