#UVa:10055-Hashmat the Brave Warrior

灆洢 2011-11-29 22:28:29

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

C++(0.136)

/*******************************************************/
/* UVa 10055 Hashmat the brave warrior                 */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2011/11/29                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
  long long warrior1, warrior2;
  while( scanf( "%lld%lld", &warrior1, &warrior2 ) != EOF ){
    printf( "%lld\n", (warrior1 > warrior2)? warrior1-warrior2 : warrior2-warrior1 ); 
  }
  return 0;
}

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料