思路简单好写
判断如果是大写就asc码+32转换成小写;
然后再先判断字符长度,分三类讨论:
如果在循环的长度短的字符串结束之前,有出现词典序大小比较不一样,就优先按照这个来,如果完全一致,那就字符串长度长的那个更大
eg长度a>b且在长度b范围内字符完全一致(上面bool为真),但因为a更长,所以输出>
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a[100], b[100];
cin.getline(a, 100);
cin.getline(b, 100);
bool w = false;
for (int i = 0; i < max(strlen(a),strlen(b)); i++) {
if (a[i] >= 65 && a[i] <= 91) {
a[i] = a[i] + 32;
}
if (b[i] >= 65 && b[i] <= 91) {
b[i] = b[i] + 32;
}
}
if (strlen(a) == strlen(b)) {
for (int i = 0; i < strlen(a); i++) {
if (strcmp(&a[i], &b[i]) == 0) {
w = true;
continue;
}
else if (strcmp(&a[i], &b[i]) < 0) {
cout << "<";
break;
}
else if (strcmp(&a[i], &b[i]) > 0) {
cout << ">";
break;
}
}
if (w) cout << "=";
}
else if (strlen(a) > strlen(b)) {
for (int i = 0; i < strlen(b); i++) {
if (strcmp(&a[i], &b[i]) == 0) {
w = true;
continue;
}
else if (strcmp(&a[i], &b[i]) < 0) {
cout << "<";
break;
}
else if (strcmp(&a[i], &b[i]) > 0) {
cout << ">";
break;
}
}
if (w) cout << ">";
}
else if (strlen(a) < strlen(b)) {
for (int i = 0; i < strlen(a); i++) {
if (strcmp(&a[i], &b[i]) == 0) {
w = true;
continue;
}
else if (strcmp(&a[i], &b[i]) < 0) {
cout << "<";
break;
}
else if (strcmp(&a[i], &b[i]) > 0) {
cout << ">";
break;
}
}
if (w) cout << "<";
}
return 0;
}