Run ID:82431

提交时间:2024-07-13 11:21:18

#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; }