[題解] UVA - 10055 - Hashmat the brave warrior

Hashmat the brave warrior

Posted by Hsu on September 10, 2023

題目來源

UVa 10055

題意

  • 給你兩個數字,相減求絕對值

思路

  • 超級大水題,需要注意幾點
    • 整數存取範圍是$2^{63}$,所以用long long int
    • 用EOF的方式輸入
    • 相減求絕對值:用abs()
    1
    2
    3
    4
    
      long long int a,b;
      while (cin>>a>>b){
      	cout<<abs(a-b)<<endl;
      }
    

參考解答

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    long long int a,b;
    while (cin>>a>>b){
        cout<<abs(a-b)<<endl;
    }
    return 0;
}