URL: http://blog.csdn.net/laciqs/article/details/6637139
本来以为题目很简单,结果wa了两次,万事小心点儿,容易打击自信不是~
猥琐的题目,看起来傻子都会,实际有两个陷阱:
1. Hashmat's soldier number is never greater than his opponent.
看到这里本以为用b-a就完事了,而input下面还有一句:
These two numbers in each line denotes the number of soldiers in Hashmat's army and his opponent's army or vice versa
最后有个反之亦然,就是输入可能倒过来,先输入哪方的士兵人数都不一定,所以要求绝对值。
2. The input numbers are not greater than 2^32.
看到2^32很眼熟,本会因为int足矣,其实int的范围查一下就知道并不够,所以要用更大的类型,经试验,unsigned不行,用long long也太麻烦了点,最好是这样写:
#include <stdio.h>
#include <math.h>
int main(void)
{
double a, b;
while (scanf("%lf%lf", &a, &b) == 2)
printf("%.0f\n", fabs(a-b));
return 0;
}