Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
91864 sh25_shenpy 字符串对比 C++ 通过 0 MS 268 KB 1257 2026-06-17 20:19:05

Tests(4/4):


#include <iostream> #include <string> #include <algorithm> // for transform #include <cctype> // for tolower/toupper using namespace std; int main() { // 优化IO ios::sync_with_stdio(false); cin.tie(NULL); string s1, s2; if (!(cin >> s1)) return 0; if (!(cin >> s2)) return 0; // 1. 判断长度是否相等 if (s1.length() != s2.length()) { cout << 1 << endl; return 0; } // 2. 判断是否完全一致(区分大小写) bool exact_match = true; for (size_t i = 0; i < s1.length(); ++i) { if (s1[i] != s2[i]) { exact_match = false; break; } } if (exact_match) { cout << 2 << endl; return 0; } // 3. 判断是否忽略大小写一致 bool case_insensitive_match = true; for (size_t i = 0; i < s1.length(); ++i) { // 将两个字符都转换为小写进行比较 if (tolower(s1[i]) != tolower(s2[i])) { case_insensitive_match = false; break; } } if (case_insensitive_match) { cout << 3 << endl; return 0; } // 4. 其他情况 cout << 4 << endl; return 0; }


测评信息: