好吧,其实这个题我调了很多·次,主要是因为摩斯密码是伪造的。
也就是说,你要找出 O 和 K 分别对哪个斯莫尔斯电码。
突破点:OOK 和 OK。
因为 OK 是 OOK 的真子集,所以我们可以关注后面的部分,在 OOK 的电码减掉 OK 的电码过后剩下了 .-.- 这个电码,这就是 O 的电码,从而得到 .- 就是 K 的电码。
AC code
AC code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
string result;
for (int i = 0; i < s.size(); i++) {
if (s[i]=='O') {
result += ".-.-";
} else if (s[i] == 'K') {
result += ".-";
}
}
cout << result << endl;
return 0;
}