解题思路:
注意事项:
字符串比较函数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 人评分
拆分位数 (C语言代码)浏览:1327 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:664 |
2006年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:669 |
分糖果 (C语言代码)浏览:920 |
C语言训练-大、小写问题 (C语言代码)浏览:681 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:597 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:754 |
上车人数 (C语言代码)浏览:713 |
整除的尾数 (C语言代码)浏览:814 |
1005答案错误为什么浏览:1975 |