【題解】ZeroJudge a518: 12468 – Zapping

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=a518
【解題想法】

  • (Line-8) 題目未保證 a <= b
  • 0 – – – a – – – b – – – 99 – 0
    • 按上鍵:b – a
    • 按下鍵:a + 1 + ( 99 – b ) = 100 + a – b
#include <iostream>
using namespace std;

int main() {
    int a, b;
    while (cin >> a >> b){
        if (a == -1 && b == -1) break;
        if (a > b) swap(a, b);
        cout << min(b-a, 100+a-b) << "\n";
    }
    return 0;
}
分享本文 Share with friends