唯一的陷阱就是在於數值範圍,
剛好到2^32,就連unsigned int也會爆,
所以請用long long吧!
P.S. C語言的abs不太支援long long Orz...
[C](2ms, 272KB)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
[C++](4ms, 696KB)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
long long x, y; | |
while( cin >> x >> y ) | |
cout << abs( x-y ) << endl; | |
return 0; | |
} |
0 意見:
張貼留言