资源限制
时间限制:1.0s 内存限制:256.0MB
问题描述
比较两个字符串s1和s2,输出:0表示s1与s2相等;1表示s1的字母序先于s2;-1表示s1的字母序后于s2
输入格式
输入两行,第一行输入一个字符串1,第二行输入字符串2。
输出格式
输出比较的结果
样例输入
abc
abd
样例输出
1
样例输入
English
English
样例输出
0
样例输入
hello
ha
样例输出
-1
解题思路:
这道题如果用传统的思路,就是按位比较,并进行判断的方式,太繁琐且容易出错,如果使用string类型的数据,直接比较即可,方便快捷,代码如下:
#include<bits/stdc++.h>
using namespace std;
int main(){
string s1, s2;
cin >> s1 >> s2;
if(s1 == s2){
cout << "0";
}else if(s1 < s2){
cout << "1";
}else{
cout << "-1";
}
return 0;
}