UVa 10055 - Hashmat the Brave Warrior
来源:互联网 发布:网络爬虫实战 编辑:程序博客网 时间:2024/06/07 04:53
时间限制:3秒
Hashmat 是个勇敢的战士,带着一票年轻的战士们跑去打仗。然后打仗之前他要先对比一下自己人数比对面人数差多少,然后决定打不打(Hashmat 的人数始终比对面少)……
真是勇敢的战士……嗯……
输入是一行两个数,分别是Hashmat 的人数和对面的人数,或者反过来。人数不大于2^32,输入读到EOF结束。
输出两边人数差多少。
其实就是输入两个数输出差的绝对值。
注意的地方其实就两个:
一个小坑是两个数谁大谁小不确定,虽然原文里Hashmat 的人数一定小于对面,但是输入次序不一定是Hashmat在前。
另一个坑是数据不大于2^32,也就是说可能等于2^32,超出了int的上限。
当年刷UVa的一血就这个……
#include <iostream>using std::cin;using std::cout;using std::endl;int main() { unsigned long long a, b; while(cin >> a >> b) { cout << (a > b ? a - b : b - a) << endl; } return 0;}
哎哎!?
好像UVa可以交Python3的代码了欸,甚好,甚好……
顺手写了个Python3版本的,不过这个EOF好像略烦啊……不知道这么写是不是标准做法……
while True: try: line = input() except EOFError: break data = [int(i) for i in line.split()] a = data[0] b = data[1] print(abs(a - b))
0 0
- UVa OJ 10055-Hashmat the Brave Warrior
- UVa:10055 - Hashmat the Brave Warrior
- UVa 10055 Hashmat the brave warrior
- uva 10055 Hashmat the Brave Warrior
- UVA 10055 - Hashmat the Brave Warrior
- uva-10055 - Hashmat the Brave Warrior
- uva 10055 Hashmat the Brave Warrior
- UVa OJ 10055 - Hashmat the Brave Warrior
- UVa 10055 - Hashmat the Brave Warrior
- UVA 10055 Hashmat the brave warrior
- uva 10055 Hashmat the brave warrior
- UVa 10055 Hashmat the brave warrior
- UVA 10055 Hashmat the brave warrior
- UVA - 10055 - Hashmat the Brave Warrior
- uva 10055 - Hashmat the Brave Warrior
- UVA OJ: 10055 - Hashmat the Brave Warrior
- UVa 10055 - Hashmat the Brave Warrior
- UVA 10055 Hashmat the Brave Warrior
- RabbitMQ Exchange 模式 - direct
- A-Home Number
- PHP CI框架中实现事物回滚
- 从服务器获取数据(json数据,json集合数组数据)并解析
- 乐学成语——数据库创建(导入、打开)
- UVa 10055 - Hashmat the Brave Warrior
- linux系统下查看swap
- miniUI中的窗口关闭
- Volley 源码解析(一)
- Spring MVC 3.0 深入及对注解的详细讲解
- 多线程
- JSP基础
- IOS Dev Intro - NSOperation of Thread Series
- js里任意两个数之间的随机数函数