Codeforces Beta Round #85 (Div. 2 Only) A. Petya and Strings

http://codeforces.com/problemset/problem/112/A

题意:
无视大小写的情况下,比较2个字符串的字典序大小。
a大于b输出1,小于输出-1,等于则为0。

PS:
字典序:a最小,z最大。aa < ab;
因为C++刚好支持对字符串的大小比较,并且重载了== > <三个符号。
但需要先都转为小写。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bits/stdc++.h>
using namespace std;

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