英文題目傳送門,中文題目傳送門
看了看題目,解題過程有以下幾個重點
看了看題目,解題過程有以下幾個重點
- 輸入輸出不會大於2^32,但是2^32本身就超過long int可以表述的範圍了,所以要用long long int,在scan跟printf要用%lld來截取跟輸出
- 題目說Hashmat's soldier number is never greater than his opponent.是騙人的!如果只將敵人數目-Hashmet兵將數目是不會過的...需要加入判斷式決定減數跟被減數
/*******************************************************/
/* UVa 10055 Hashmat the brave warrior */
/* Author: Near Lin */
/* Version: 2015/07/07 */
/*******************************************************/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
long long int hashmet, opponent ;
while(scanf("%lld%lld", &hashmet, &opponent) != EOF){
printf("%lld\n", (hashmet > opponent) ? hashmet - opponent : opponent - hashmet);
}
return 0;
}
紀錄一下這題的重點,C的資料表示與範圍:
int (32 bits): -2^(31)-1 ~ 2^(31)-1, (%d)(%i)
unsign int (32 bits): 0 ~ 2^(32)-1, (%u)
long int (32 bits): -2^(31)-1 ~ 2^(31)-1, (%ld)
unsign long (32 bits): 0 ~ 2^(32)-1, (ULONG_MAX)(%lu)
long long int (64 bits): -2^(63)-1 ~ 2^(63)-1, (%lld)
unsign long (64 bits): 0 ~ 2^(64)-1, (ULONG_MAX)(%llu)
這封郵件來自 Evernote。Evernote 是您專屬的工作空間,免費下載 Evernote |
Comments
Post a Comment