大于输出1,小于是-1,相等是0.
刚好C++的STL里有string的逻辑运算符重载,直接==、>、<就可以比较了 (注意,string的比较似乎是和大小写相关的所以我们要把它变成全大写或者全小写)
Code:
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
// http://codeforces.com/contest/112
// Petya and Strings
int main()
{
string a,b; cin>>a>>b;
for(int i=0;i<a.length();i++)
{
a[i]=tolower(a[i]);
b[i]=tolower(b[i]);
}
if(a==b) cout<<0;
else if(a>b)cout<<1;
else cout<<-1;
return 0;
}

本文介绍了一种方法,用于比较两个相同长度的字符串的字典序大小,忽略大小写差异。通过将字符串统一转换为小写形式,利用C++ STL中的string类实现比较,并返回相应的比较结果。
511

被折叠的 条评论
为什么被折叠?



