這題在學什麼
將代號以字串讀入,保留前導零;九個字元全部參與最大兩位的選取。
複製後排序,取末兩個數字,重複值只要來自不同位置就可同時使用。
末三位轉成整數後比對平方和,依結果輸出 Good Morning! 或 SPY!。
Step-by-step animation
身分驗證機制・全九位取前兩大
步驟 1 / 3
九位全部參與
代號是 980000145,末三位 145 也在選取範圍內。
9
8
0
0
0
0
1
4
5
- 末三位
- 145
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
string t = s;
sort(t.begin(), t.end());
int a = t[8] - '0', b = t[7] - '0';
cout << (a * a + b * b == stoi(s.substr(6)) ? "Good Morning!" : "SPY!") << '\n';
}
先試著自己完成,再切換語言比對解法。參考程式可複製到題目編輯器。