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

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

Sample Output

  1. 10
  2. 15
  3. 6
  • 第一次提交没有注意到between,OJ返回Presentation Error

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

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

Solution

  1. #include <cstdio>
  2. using namespace std;
  3. #define DEBUG 0 //本地调试定义为1, 提交时定义为0
  4. #if DEBUG
  5. #else
  6. #define fp stdin //当DEBUG被定义为0时, fp被替换为stdin
  7. #endif
  8. int main() {
  9. #if DEBUG
  10. FILE* fp;
  11. fp = fopen("a.txt", "r"); //a.txt作为文件输入
  12. #endif
  13. int n;
  14. while (fscanf(fp, "%d", &n) != EOF) {
  15. break;
  16. }
  17. int* sum_arr = new int[n];
  18. for (int i = 0; i < n; i++) {
  19. int m;
  20. while (fscanf(fp, "%d", &m) != EOF) {
  21. break;
  22. }
  23. int sum = 0;
  24. for (int j = 0; j < m; j++) {
  25. int add;
  26. while (fscanf(fp, "%d", &add) != EOF) {
  27. break;
  28. }
  29. sum += add;
  30. }
  31. sum_arr[i] = sum;
  32. }
  33. for (int i = 0; i < n; i++) {
  34. printf("%d\n", sum_arr[i]);
  35. if (i < n - 1) {
  36. printf("\n");
  37. }
  38. }
  39. delete[] sum_arr;
  40. return 0;
  41. }

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

  1. #ifdef DEBUG
  2. #else
  3. #define fp stdin
  4. #endif
  5. int main() {
  6. #ifdef DEBUG
  7. FILE* fp;
  8. fp = fopen("a.txt", "r");
  9. #endif

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

  1. $ g++ 1.1.8.cpp -DDEBUG

运行

  1. $./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. [bug]spring项目通过反射测试私有方法时,注入对象异常

    背景 遇到问题:在进行Spring单元测试编写时,发现被测方法是一个私有方法,无法直接通过注入对象调用 解决思路:首先想到通过反射获取该私有方法的访问权限,并传入注入对象,最终调用对象的私有方法. 出 ...

  2. Tomcat中的一些问题

    问题: 一闪而过,解决办法: 用记事本打开startup.bat文件,在最下面添加pause 再次运行,发现问题 CATALINA_HOME是TOMCAT安装路径的别名, 计算机>属性>环 ...

  3. 在python3.6环境下使用cxfreeze打包程序

    在python3.6环境下使用cxfreeze打包程序 环境:python3.6 打包程序:aliens_invasion 原本想使用pyintaller 进行打包,使用pip的安装过程也没有问题,打 ...

  4. Qt学习日记篇-Qt中使用Curl和jsonCpp

    1.Qt中安装并使用jsonCPP库 1.1  官网下载.https://sourceforge.net/projects/jsoncpp/    解压文件得到 jsoncpp-src-0.5.0 文 ...

  5. Excel 快速跳转到工作表

    新建 vba 模块 Sub GotoSheet() tname = InputBox("input table name") If StrPtr(tname) = 0 Then E ...

  6. appium+python运行自动化测试提示“find_element() takes from 1 to 3 positional arguments but 14 were given”错误

    1.运行后提示"find_element() takes from 1 to 3 positional arguments but 14 were given",在网上找了很多解决 ...

  7. 机器学习之支持向量机(python)

    参考链接:https://blog.csdn.net/weixin_33514582/article/details/113321749.https://blog.csdn.net/weixin_44 ...

  8. Python习题集(十一)

    每天一习题,提升Python不是问题!!有更简洁的写法请评论告知我! https://www.cnblogs.com/poloyy/category/1676599.html 题目 如果一个正整数等于 ...

  9. IPSec协议框架

    文章目录 1. IPSec简介 1.1 起源 1.2 定义 1.3 受益 2. IPSec原理描述 2.1 IPSec协议框架 2.1.1 安全联盟 2.1.2 安全协议 报文头结构 2.1.3 封装 ...

  10. 简说yuv

    最近弄了一个读取y4m文件转成yuv的流的事情,记录一些yuv相关的细节 为什么会有yuv 因为我们目前的显示器显示的原理都是三原色,几乎所有的视频数据最后都要转为rgb格式才能渲染到显示屏上,而原始 ...