算法1
思路:这个思路太巧妙了,绝了,将两组字符串利用tolower()函数转化成小写,直接对比
再次见到“for(auto &c:a)”,nice
C++ 代码
#include<iostream>
using namespace std;
int main(){
string a,b;
getline(cin,a);getline(cin,b);
for(auto &c:a) c=tolower(c);
for(auto &c:b) c=tolower(c);
if(a==b) puts("=");
else if(a<b) puts("<");
else puts(">");
return 0;
}
算法2
思路:这个是我第一次写的时候,没有字符转换大小写函数
C++ 代码
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string a,b;
getline(cin,a);
getline(cin,b);
for (int i = 0; i < a.size(); i ++)
if (a[i] >= 'A' && a[i] <= 'Z') a[i] += 32;
for (int i = 0; i < b.size(); i ++)
if (b[i] >= 'A' && b[i] <= 'Z') b[i] += 32;
int c;
c = strcmp(a.c_str(),b.c_str());//注意这里a.c_str(),第一次直接用直接比较,一直报错
if(c < 0) cout << "<";
if(c == 0) cout << "=";
if(c > 0) cout << ">";
return 0;
}