Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
82431 赵文浚 31忽略大小写的字符串比较 C++ Wrong Answer 0 MS 260 KB 942 2024-07-13 11:21:18

Tests(0/10):


Code:

#include <iostream> #include <cstring> int ignoreCaseStrcmp(const char* str1, const char* str2) { int i = 0; while (str1[i] && str2[i]) { char c1 = tolower(str1[i]); char c2 = tolower(str2[i]); if (c1 < c2) { return -1; } else if (c1 > c2) { return 1; } i++; } if (!str1[i] &&!str2[i]) { return 0; } else if (!str1[i]) { return -1; } else { return 1; } } int main() { char str1[] = "Hello"; char str2[] = "hello"; int result = ignoreCaseStrcmp(str1, str2); if (result == 0) { std::cout << "两个字符串相等" << std::endl; } else if (result < 0) { std::cout << "第一个字符串小于第二个字符串" << std::endl; } else { std::cout << "第一个字符串大于第二个字符串" << std::endl; } return 0; }


Run Info:

------Input------
abc E abc E
------Answer-----
=
------Your output-----
两个字符串相等