1 条题解
-
0
练68.2 字符串判等
解题思路
逐行读两个串,删除空格并把剩余字母统一转为小写,比较处理后的串是否一致。
正确性说明
依题目给出的对应关系逐项处理,位置与原输入保持明确对应。每一步完成当前项的全部贡献,结束后得到所有位置或字符的目标结果。
易错点
忽略的是空格,不是重排单词。
复杂度
时间O(L),空间O(L)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string a, b; getline(cin, a); getline(cin, b); auto normalize = [](string s) { string t; for (unsigned char c : s) if (c != ' ') t += char(tolower(c)); return t; }; cout << (normalize(a) == normalize(b) ? "YES" : "NO") << "\n"; return 0; }
- 1