1 条题解

  • 0
    @ 2026-1-30 12:33:04
    #include<bits/stdc++.h>
    using namespace std;
    
    // 辅助函数:去除字符串末尾的回车和换行符
    string trimRight(const string& s) {
        int end = s.length() - 1;
        while (end >= 0 && (s[end] == '\n' || s[end] == '\r' || s[end] == ' ')) {
            end--;
        }
        return s.substr(0, end + 1);
    }
    
    int main() {
        string s1, s2;
        
        // 读取输入
        getline(cin, s1);
        getline(cin, s2);
        
        // 去除可能的尾部空白字符(包括\r\n)
        s1 = trimRight(s1);
        s2 = trimRight(s2);
        
        // 预处理字符串
        string c1 = "", c2 = "";
        
        // 处理s1:去除空格,大写转小写
        for (char ch : s1) {
            if (ch == ' ') continue;  // 跳过空格
            if (ch >= 'A' && ch <= 'Z') {
                c1 += ch + ('a' - 'A');  // 大写转小写
            } else {
                c1 += ch;
            }
        }
        
        // 处理s2:去除空格,大写转小写
        for (char ch : s2) {
            if (ch == ' ') continue;  // 跳过空格
            if (ch >= 'A' && ch <= 'Z') {
                c2 += ch + ('a' - 'A');  // 大写转小写
            } else {
                c2 += ch;
            }
        }
        
        // 比较并输出结果
        if (c1 == c2) {
            cout << "Yes!";
        } else {
            cout << "No!";
        }
        
        return 0;
    }
    
    • 1

    信息

    ID
    129
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    12
    已通过
    1
    上传者