CF94A Restoring Password 題解
阿新 • • 發佈:2021-12-21
CF94A Restoring Password 題解
Content
有一個 \(80\) 位的 \(01\) 字串,由 \(8\) 個長度為 \(10\) 的 \(01\) 字串組成,每個小字串分別對應一個數字。現在,給出這個字串和 \(0\) ~ \(9\) 分別對應的 \(01\) 字串,請你破解出這個字串對應的數字。
Solution
這麼好的題目為什麼不用 \(\texttt{map}\) 呢……
分別將 \(0\) ~ \(9\) 的字串分別對映到對應的數字,然後看每 \(10\) 位字串分別對應那些數字,就可以直接用 \(\texttt{map}\) 映射出來了。
Code
#include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <iostream> #include <map> using namespace std; string s[17]; map<string, int> num; int main() { for(int i = 0; i <= 10; ++i) { cin >> s[i]; if(i) num[s[i]] = i - 1; } int len = s[0].size(); for(int i = 0; i < len; i += 10) { string tmp = ""; for(int j = 0; j < 10; ++j) tmp += s[0][i + j]; printf("%d", num[tmp]); } return 0; }