HDU 1.1.2解题报告
2015-03-08 11:20
357 查看
第二个A+B问题,稍微进行了改动,以下是大致题意。
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.
表达的意思大致是,输入的第一行是一个整数N,代表你要做加法的次数,然后后面的N行就是N个A+B
这样的话就要思考,怎么样控制计算A+B的次数和你的输入的N有关了,想到用循环来处理。
。
如果用c语言呢?
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.
表达的意思大致是,输入的第一行是一个整数N,代表你要做加法的次数,然后后面的N行就是N个A+B
这样的话就要思考,怎么样控制计算A+B的次数和你的输入的N有关了,想到用循环来处理。
#include <iostream> using namespaces std; int main() { int n,a,b; cin>>n; while(n&&cin>>a>>b) {cout<<a+b<<endl; --n;} return 0; }结果是显而易见的,输入N之后,利用while来控制,条件是n&&cin>>a>>b,cin>>a>>b保证a和b一直在输入,而这个n,实际上应该是n!=0的简写,我在每一次输出a+b之后,进行--n操作,将n减1,这样当n减至0时,循环结束,而刚好进行a+b的次数就等于n。这样,就实现了题目的要求
。
如果用c语言呢?
#include <stdio.h> int main() { int a,b,n; scanf("%d",&n); while(n&&scanf("%d%d",&a,&b)!=EOF) {printf("%d\n",a+b); n--; } return 0; }道理是一样的。
相关文章推荐
- Hdu 1084 What Is Your Grade?解题报告
- HDU--2104--hide handkerchief--解题报告(辗转相除的运用)
- hdu 1064 解题报告
- HDU 2680 Choose the best route 解题报告
- HDU 3732 Ahui Writes Word 解题报告
- hdu 1102 pku 2421 解题报告
- HDU 1870 愚人节的礼物 解题报告
- HDU 2469 Fire-control System解题报告
- hdu 2139解题报告
- HDU 1231 畅通工程 解题报告
- HDU第11版解题报告(农夫版)
- hdu 2516解题报告
- HDU 3335 解题报告
- hdu 1019解题报告
- hdu 1097解题报告 快速幂乘 通常方法
- Hdu 1009 FatMouse' Trade解题报告
- HDU 3336 解题报告
- 终曲(hdu 2572)解题报告
- HDU 1158 Emloyment Planning 解题报告
- HDU 1856 More is better 解题报告