字符串对比
来源:互联网 发布:香港中老年人奶粉知乎 编辑:程序博客网 时间:2024/05/16 14:39
题目:
给定两个仅由大写字母或小写字母组成的字符串(长度介于1到10之间),它们之间的关系是以下4中情况之一:
1:两个字符串长度不等。比如 Beijing 和 Hebei
2:两个字符串不仅长度相等,而且相应位置上的字符完全一致(区分大小写),比如 Beijing 和 Beijing
3:两个字符串长度相等,相应位置上的字符仅在不区分大小写的前提下才能达到完全一致(也就是说,它并不满足情况2)。比如 beijing 和 BEIjing
4:两个字符串长度相等,但是即使是不区分大小写也不能使这两个字符串一致。比如 Beijing 和 Nanjing
编程判断输入的两个字符串之间的关系属于这四类中的哪一类,给出所属的类的编号。
输入格式
包括两行,每行都是一个字符串
输出格式
仅有一个数字,表明这两个字符串的关系编号
样例输入
BEIjing
beiJing
样例输出
3
代码:
#include<iostream>#include<cstring>using namespace std;int main(){ char str1[11],str2[11]; int type; cin>>str1; cin>>str2; if(strlen(str1)!=strlen(str2)) cout<<"1"; else{ if(!strcmp(str1,str2)) cout<<"2"; else if(!strcmpi(str1,str2)) cout<<"3"; else cout<<"4"; } cout<<endl; return 0;}
0 0
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串对比
- 字符串 对比 equals
- 字符串Hash函数对比
- 字符串Hash函数对比
- 字符串Hash函数对比
- java——流(Stream)、文件(File)和IO
- 《Go in Action 2015.11.pdf》之Go’s type system
- 泛型擦除的局限
- super()在程序中的实现与Object类中的toString()方法的实现
- 汉诺塔问题
- 字符串对比
- spring+mybatis数据源切换【service层以及controller层】
- c++ 栈机制
- JAVA读取并将图片转换成String
- 集合(2)—Collection之List的使用方法
- 关于重载和重写
- ES6---let与const
- 用Unity做游戏,你需要深入了解下IL2CPP
- OpenCV--C4996'fopen': This function or variable may be unsafe.