STL


私信TA

用户名:542013460649

访问量:2244

签 名:

等  级
排  名 13852
经  验 851
参赛次数 0
文章发表 7
年  龄 0
在职情况 学生
学  校 郑州轻工业大学
专  业

  自我简介:

解题思路:

注意事项:

字符串比较函数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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区