解题思路:
注意事项:
字符串比较函数strcmp的比较,两个字符串自左向右逐个字符相比(按ASCII值大小相比较),
直到出现不同的字符或遇’\0’为止。
基本形式为strcmp(str1,str2),若str1=str2,则返回零;若str1<str2,则返回负数;若str1>str2,则返回正数
原型:extern int strcmp(const char *s1,const char * s2);
注意不能比较string类
参考代码:
#include<iostream> #include<string> #include<cstring> using namespace std; int main() { char s1[1000]; char s2[1000]; cin>>s1; cin>>s2; int flag=strcmp(s1,s2); if(flag>0) cout<<"1"; else if(flag<0) cout<<"-1"; else cout<<"0"; return 0; }
0.0分
1 人评分