解题思路:
注意事项:
字符串比较函数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 人评分
一个简单易懂的代码浏览:1156 |
点我有惊喜!你懂得!浏览:1977 |
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:667 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:1053 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:1203 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:509 |
Biggest Number (C++代码)回溯法浏览:1612 |
字符串输入输出函数 (Java代码)浏览:1437 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:676 |
C语言考试练习题_排列 (C语言代码)浏览:719 |