CF 112A Petya and Strings
来源:互联网 发布:国家与地区顶级域名 编辑:程序博客网 时间:2024/06/05 01:15
题解:
两组字符串,比较;
规则:如果大写,换小写;
后一个字符进行比较,A大1,B大-1,否则0;
看题长度是默认相同的,就求了长度比较;
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two stringslexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Each of the first two lines contains a bought string. The strings' lengths range from1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
aaaaaaaA
0
absAbz
-1
abcdefgAbCdEfF
1
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order
AC代码:
#include <bits/stdc++.h>using namespace std ;int main(){char a[5000] , b[5000] ;cin>>a>>b;int flag;flag=0;int len =strlen(a);for(int i = 0 ; i<len ;i++){if(a[i]>='A'&&a[i]<='Z'){a[i]+=32;}if(b[i]>='A'&&b[i]<='Z'){b[i]+=32;}if(a[i]>b[i]){printf("1\n");flag=1;break;}else if(a[i]<b[i]){printf("-1\n");flag=1;break;}else {continue;flag=0;}}if(flag==0){printf("0\n");}return 0;}
- CF:112A.Petya and Strings
- CF 112A Petya and Strings
- 112A - Petya and Strings
- 112A - Petya and Strings
- A. Petya and Strings
- codeforces 112A Petya and Strings
- 【CodeForces】A. Petya and Strings
- Problem--112A--Codeforces--A. Petya and Strings
- Codeforces 112A-Petya and Strings(实现)
- CodeForces 112 A.Petya and Strings(水~)
- 【string比较】#85 A. Petya and Strings
- cf 66A Petya and Java
- Petya and Strings
- Coderforces Petya and Strings
- Codeforces刷题之路——112A Petya and Strings
- A. Vasya and Petya's Game(cf第一题)
- CF 518A(Vitaly and Strings-构造)
- CF(#293 div2):A:Vitaly and Strings
- 深度学习研究组Deep Learning Research Groups
- jQuery--选择器详解
- 《leetCode》:Single Number III
- Mac一些基本常用快捷键的使用
- WebAssembly你需要了解的7件事
- CF 112A Petya and Strings
- Linux技术——netstat命令详解
- Java排序算法总结之(二)——基于交换排序(冒泡排序、快速排序)
- Git的学习笔记(一)——初识Git及版本库的管理
- 第一次接触的cocoaPods
- ARM引导过程(s5pv210)
- Hive 层次查询
- 运行jar文件
- 求凸包 卷包裹