[HDU1000] A + B Problem
Problem Description
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
分析
输入两个数A和B,求A+B。
但是是多行的,因此需要用循环反复读取。
又因为输入数据中没有说有多少行,因此不能使用计数循环,而要通过while循环判断是否到达文件尾,如果是则停止循环。
而在循环中则是将输入的两个数的和算出,并输出。
因此C/C++代码如下:
C
#include <stdio.h>
int main()
{
int a, b;
while (scanf("%d%d", &a, &b) != EOF)
printf("%d\n", a + b);
return ;
}
C++
C++和C区别不大,仅仅是<stdio.h>和<iostream>,printf和cout,scanf和cin,以及如何判断EOF。
#include <iostream>
int main()
{
int a, b;
while (cin >> a >> b)
cout << (a + b) << endl;
return ;
}
[HDU1000] A + B Problem的更多相关文章
- A + B Problem,hdu-1000
A + B Problem Problem Description Calculate A + B. Input Each line will contain two integers A and ...
- 【HDU1000】A+B Problem
题目来源:www.acm.hdu.edu.cn 题目编号:1000 A+B Problem /*----------------------------------------原题目-------- ...
- A + B Problem(hdu1000)
注意,认真读题目的Input要求,看看是输入一组测试数据还是输入多组测试数据.输入多组数据,不要忘记while(). #include<iostream> using namespace ...
- A+B Problem && OJ推荐【持续更新】
目录 List 前言 长郡 Position: code 1. 2. 持续更新,么么哒 List 前言 有没有觉得写这篇文章很奇怪,这个还是有原因的.①很多OJ都有着道题,所以发个博客②这可以介绍很多 ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
随机推荐
- Linux-进程描述(2)之进程标识符与进程位置
在上一篇文章中详细介绍了task_struct结构体内的常见成员,然后我们就来看一下具体内容.每个进程都把它的信息放在 task_struct 这个数据结构中,task_struct 包含了这些内容: ...
- 读《effective C++》1
条款一:视C++为一个语言联邦 学习C++半个月了,学了他的面向过程编程,面向对象编程(封装性,继承性,多态性),template泛型编程,开始只是觉得C++基础是面向对象,但是学了这么多块开始有点迷 ...
- 记一次 Newtonsoft.Json 巧妙的用法(C#)
数据添加的功能 有一个表格提交数据如下: 是否选择和文本值.分开保存到数据库太麻烦.取得时候也麻烦 想到了存成json数据.一个字段就可以了. html代码: <table class=&quo ...
- JavaWeb开发之HttpServletResponse
1. HttpServletResponse简介 Web服务器回送给Web客户端的HTTP响应消息分为三个部分:状态行,响应消息头,响应体. Servlet API中定义了ServletRespons ...
- node.js系列(实例):原生node.js实现静态资源管理
/** * node入门之综合案例(一):简易路由 * @Author : by Ghost * @Date : 2016/07/11 * @Description : * 1.引入以下模块 * ht ...
- 从花式swap引出的pointer aliasing问题
上次,一个同学问我,你知不知道可以不用引入中间变量就可以实现swap? 我说,我知道,可以用加减法或者异或实现,像是这样 void mySwap(int &x,int &y) { x= ...
- 关于定时发送服务的解决办法(PHP)
一.定时发送任务解析 在进行手机APP或者微信开发的时候,经常会有需要定时推送消息的场景. 定时发送又分为两种: 一种是在开发的时候固定时间,后台管理人员只能选择将要推送的消息: 另一种是后台管理人员 ...
- list、set、map区别
list是有序且重复的; list中的数据都是按照写入的顺序排列的,存入list的数据用add方法写入; list可以用循环遍历list以达到获取全部数据的目的,同时也可以通过下标get(index) ...
- Linux环境下用户空间与内核空间数据的交换方式
在linux环境开发过程中,经常会需要在用户空间和内核空间之间进行数据交换. 介绍了 Linux 系统下用户空间与内核空间数据交换的几种方式 第一节:使用procfs实现内核交互简明教程(1) 第二节 ...
- 蓝桥杯-组素数-java
/* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2016, 广州科技贸易职业学院信息工程系学生 * All rights reserved. * 文件名称: ...