本站遷移

因為我最近租用了網路空間以及網域,
故本站已遷移至新網站~
這邊的資訊已經正在進行搬移的工作~
希望各位可以到新網站去逛XD

New Website:
http://knightzone.org/

搜尋此網誌

2011年1月18日 星期二

[Zerojudge]a012: Hashmat的戰役

這題只要將兩個數絕對值相減即可,
唯一的陷阱就是在於數值範圍,
剛好到2^32,就連unsigned int也會爆,
所以請用long long吧!

P.S. C語言的abs不太支援long long Orz...

[C](2ms, 272KB)
#include<stdio.h>
#include<stdlib.h>
int main()
{
long long x, y;
while( scanf( "%lld%lld", &x, &y ) != EOF )
printf( "%lld\n", ( x-y > 0 )? x-y : y-x );
return 0;
}
view raw ACM10055.c hosted with ❤ by GitHub


[C++](4ms, 696KB)
#include<iostream>
using namespace std;
int main()
{
long long x, y;
while( cin >> x >> y )
cout << abs( x-y ) << endl;
return 0;
}

0 意見:

張貼留言