這題在學什麼
T 應以字串讀入,指定的 N 也以一字元處理。
逐字保留不等於 N 的字元,得到刪除雜訊後的字串。
將保留字串與反轉結果比較,相等輸出 Yes,否則輸出 No;前導零不能丟失。
Step-by-step animation
雜訊移除・保留字元後判迴文
步驟 1 / 3
指定雜訊
8081708 中所有 8 都要刪除。
8
0
8
1
7
0
8
- noise
- 8
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string t, n, s;
cin >> t >> n;
for (char c : t)
if (c != n[0])
s += c;
string rev = s;
reverse(rev.begin(), rev.end());
cout << (s == rev ? "Yes" : "No") << '\n';
}
先試著自己完成,再切換語言比對解法。參考程式可複製到題目編輯器。