首页 > 其他 > 详细

Uva小记 01

时间:2014-02-14 12:58:58      阅读:312      评论:0      收藏:0      [点我收藏+]

今天开始敲一敲Uva里面的一些题目,决定摘一些错误信息上来备忘,fighting!

 

1.10055第一题,就写了3次才AC,简直无语,很简单的一道题目。

也许是纯英文的缘故吧,这题总共有两个需要提别注意的地方:

 

1.The input numbers are not greater than 2^32.这是一个陷阱,原以为只要整形int就可以满足了,可是wa了。int只能表示-2^32—2~32-1。所以需要用范围更大的long long型。

2.or vice versa 反之亦然。所以结果应该是个正整数。用取绝对值abs可以,用大的减去小的也行。

 

 

Hashmat the brave warrior

Input: standard input

 

 

 

Output: standard output

 

 

Hashmat is a brave warrior who with his group of young soldiers moves from one place to another to fight against his opponents. Before fighting he just calculates one thing, the difference between his soldier number and the opponent‘s soldier number. From this difference he decides whether to fight or not. Hashmat‘s soldier number is never greater than his opponent.

Input

The input contains two integer numbers in every line. These two numbers in each line denotes the number of soldiers in Hashmat‘s army and his opponent‘s army or vice versa. The input numbers are not greater than 2^32. Input is terminated by End of File.

Output

 For each line of input, print the difference of number of soldiers between Hashmat‘s army and his opponent‘s army. Each output should be in seperate line

 

Sample Input:

10 12
10 14
100 200

Sample Output:

2
4
100

 

 

[cpp] view plaincopy

 
  1. #include <iostream>  
  2. using namespace std;  
  3. int main()  
  4. {  
  5.     long long a,b;  
  6.     while(cin>>a>>b)  
  7.     {  
  8.         cout<<(a<b ? b-a :a-b )<<endl;  
  9.     }  
  10.     return 0;  
  11. }  

 

2.

Uva小记 01

原文:http://www.cnblogs.com/adamzwj/p/3548556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!