UVa OJ 10055

Problem A

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

___________________________________________________________________________________ 
Shahriar Manzoor
16-12-2000

 #include <stdio.h>
#include <math.h>
int main()
{
long long a, b;
for (;scanf("%lld%lld", &a, &b) != EOF;)
printf("%lld\n", a < b ? b - a : a - b);
return ;
}

报告:本题原以为能很容易应付,结果做了两天都没做出来,最后还是参考网上的才完成,现在说下做题出现的问题:1,没看清题意,对or vice versa这个没理解,便理所当然的把第一个当作小于第二个的数。2,2的32次方应用long long来声明定义,却用了int,没理解给出数的范围的意思,其中也暴露了我没理解int型等数据类型的取值范围。3,EOF为CTRL+Z而不是CTRL+C,导致一直出错。

原因:1,英语不熟,且粗心大意,看了个大概便做题。2理所当然了,对数据类型的不熟悉。3对文件相关标志并不理解

解决:1,只能靠学英语解决。暂无解决 。2,int型当是2个字节时,一个字节为8位,则范围是2的-15次方到2的15次方,同理,long long型是8个字节时,则范围是2的-63次方到2的63次方,至于浮点数,暂先不涉猎。3,EOF即end of file,因为文本存储方式为ascii码,则范围为0~255,不存在-1,EOF表-1,返回EOF即表结束,在windows下为CTRL+Z,而linux下则是CTRL+D。

上一篇:基於tiny4412的Linux內核移植--- 中斷和GPIO學習(3)


下一篇:我还在生产玩 JDK7,JDK 15 却要来了!|新特性尝鲜