文章目录

  • 一、Petya and Strings
  • 总结

一、Petya and Strings

本题链接

题目

A. Petya and Strings
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output

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 strings lexicographically. The letters’ case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.

Input
Each of the first two lines contains a bought string. The strings’ lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.

Output
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.

Examples

input
aaaa
aaaA

output
0

input
abs
Abz

output
-1

input
abcdefg
AbCdEfF

output
1

Note
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 <iostream>
#include <string>using namespace std;int main()
{string a, b;cin >> a >> b;int cnt1 = 0, cnt2 = 0;for (int i = 0; i < a.size(); i ++ ){if (a[i] >= 'A' && a[i] <= 'Z')a[i] = a[i] - 'A' + 'a';if (b[i] >= 'A' && b[i] <= 'Z')b[i] = b[i] - 'A' + 'a';if (a[i] > b[i]){cout << "1" << endl;exit(0);}if (a[i] == b[i]) continue;if (a[i] < b[i]) {cout << "-1" << endl;exit(0);}}cout << "0" << endl;return 0;
}

总结

string 线
uppercase 大写字母
compare 比较
lexicographically 字典学上
corresponding 相应的
equivalent 相同的
range 范围
inclusive 包含的
guaranteed 保证

水题,不解释

Petya and Strings相关推荐

  1. 112A.Petya and Strings

    112A.Petya and Strings 题目 翻译 题目 输入 输出 分析 代码 题目 翻译 题目 小Petya喜欢礼物.他妈妈为了他的生日买来了2个相同长度的字符串.字符串由大小写拉丁字母组成 ...

  2. codeforces 112APetya and Strings(字符串水题)

    A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input ...

  3. Codeforces上通过数超过5W人的题

    Codeforces上通过数超过5W人的题 共32题:1000分4题,800分28题. 编号 题号 题名 分数 通过数 1 4A Watermelon 800 x193501 2 71A Way To ...

  4. Petya and Exam

    Description It's hard times now. Today Petya needs to score 100 points on Informatics exam. The task ...

  5. Petya and Exam 模拟

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  6. B. Petya and Exam

    题目链接 It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem ...

  7. Codeforces 149 E. Martian Strings

    正反两遍扩展KMP,维护公共长度为L时,出现在最左边和最右边的位置.... 然后枚举判断... E. Martian Strings time limit per test 2 seconds mem ...

  8. Android TextView 在strings 里面 实现换行

    在TextView 把text 使用快捷键放到strings 里面 \n是无法被放到里面的 如果想实现换行 可以手动在里面添加 \n 例如写了一个小例子, 如果你写了多语言适配 ,那么在你的其他的st ...

  9. Go 学习笔记(51)— Go 标准库之 strings(字符串比较、字符串前后缀、字符串统计、字符串索引、字符串包含、字符串转换、字符串复制、字符串替换、字符串去除、字符串分割和连接)

    1. 概述说明 import "strings" strings 包实现了用于操作字符的简单函数. strings 包与 bytes 包中的函数用法基本一样. 2. 主要函数 2. ...

最新文章

  1. LeetCode简单题之独一无二的出现次数
  2. 计算机科学的大部分研究是基于,计算机科学
  3. 如何做一名优秀的电子工程师[zz]
  4. JavaScript之事件委托(附原生js和jQuery代码)
  5. git 如何删除缓存的远程分支列表
  6. sigmoid函数求导_吴恩达老师课程笔记系列第 28节 - 逻辑回归之代价函数 (4)
  7. 怎么看PLC梯形图?
  8. 苹果公司CEO乔布斯演讲的15个秘诀
  9. 哈工程转专业计算机,2021年哈尔滨工程大学大一新生转专业及入学考试相关规定...
  10. 2021年全球与中国油管线轴行业市场规模及发展前景分析
  11. 정부와동포 사고 전화해야
  12. 软件测试肖sir__python之模块
  13. 手把手教你搭建国产嵌入式模拟器SkyEye开发环境
  14. python语音标注平台_Python下的自然语言处理利器-LTP语言技术平台 pyltp 学习手札...
  15. 因为意外的遇到文件尾,PS无法打开怎么办?
  16. 使用PHP的curl爬取百度搜索页相关搜索词
  17. 蓝牙协议分析_BLE广播通信相关的技术分析
  18. 全国最好用的广告行业管理软件
  19. 西工大学计算机专业考研容易吗,2022年西北工业大学计算机专业考研难度分析及备考经验...
  20. 干货!这10个顶级资源网站,不知道实在是太可惜了!

热门文章

  1. 关于Ilegal assignment(Quart II)问题的解决
  2. 【微软 Azure 认知服务】零基础搭建微软 Azure AI 认知服务实验分享
  3. OSChina 周四乱弹 —— 为什么现在社会越来越鄙视直男
  4. MySQL 必知必会系列(一)
  5. Linux pv显示进度条命令
  6. Retina、非Retina、点、像素、iPhone分辨率
  7. Java中Ascall码的使用
  8. 【游戏客户端】剧情系统
  9. STM32开发基础知识——OLED开发基础
  10. win7 修改屏幕休眠时间