解题思路:
去除空格后,忽略字母大小写,进行比较
注意事项:
参考代码:
#include<iostream>
#include<string>
#include<limits>
using namespace std;
string check( string input) {
string s ;
for (int i = 0; i < input.size(); i++) {
if (!isspace(input[i])){
s+=input[i];
}
}
return s;
}
int main(){
string s1, s2;
getline(cin, s1);
getline(cin, s2);
s1 = check(s1);
s2 = check(s2);
int bad = 1;
for (int i = 0; i < max(s1.size(), s2.size()); i++) {
s1[i] = tolower(s1[i]);
s2[i] = tolower(s2[i]);
if (s1[i] > s2[i]) {
cout << ">" << endl;
bad = 0;
break;
}
else if (s1[i] < s2[i]) {
cout << "<" << endl;
bad = 0;
break;
}
else if (s1[i] == '\0' && s2[i] != '\0') {
cout << "<" << endl;
bad = 0;
break;
}
else if (s1[i] != '\0' && s2[i] == '\0') {
cout << ">" << endl;
bad = 0;
break;
}
}
if (bad) {
cout << "=" << endl;
}
return 0;
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:641 |
C二级辅导-计负均正 (C语言代码)浏览:607 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:575 |
校门外的树 (C语言代码)浏览:751 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:650 |
钟神赛车 (C++代码)浏览:905 |
C语言程序设计教程(第三版)课后习题9.2 (Java代码)浏览:696 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:701 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:686 |
C语言训练-求PI* (C语言代码)浏览:638 |