CF112A Petya and Strings(转发大小字符)

简介: CF112A Petya and Strings(转发大小字符)

题目描述



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.


输入格式



Each of the first two lines contains a bought string. The strings' lengths range from 11 to 100100 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.


题意翻译



输入两个字符串,大小写无关紧要,比较它们的大小。


输入格式



两个字符串(保证长度相等)


输出格式



如果第一个字符串小于第二个字符串,则输出“-1”。如果第二个字符串小于第一个字符串,则输出“1”。如果字符串相同,则打印“0”。请注意,比较字符串时不考虑字母的大小写。


输入输出样例



输入

aaaa

aaaA


输出  

0


输入  

abs

Abz


输出

-1


输入  

abcdefg

AbCdEfF


输出

1


题意分析,我们可以用string来做,也可以用char+strcmp函数来做;

我们首先要转换为同一种类型的函数,例如towlower就是转换函数


具体看代码;


char做法

#include<bits/stdc++.h>
using namespace std;
char s1[105],s2[105];
int main()
{
  cin >> s1 >> s2;
  int l1 = strlen(s1), l2 = strlen(s2);
  for (int i = 0; i < l1; i++) s1[i] = towlower(s1[i]);
  for (int i = 0; i < l2; i++) s2[i] = towlower(s2[i]);
  int ans = strcmp(s1, s2);
  printf("%d", ans==0?0:(ans>0?1:-1));
}


string做法

#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s1 ,s2 ;int ans;
  cin>>s1>>s2;
  int l1= s1.size(),l2=s2.size();
  for(int i=0;i<s1.size();i++) s1[i]=towlower(s1[i]);
  for(int i=0;i<s2.size();i++) s2[i]=towlower(s2[i]);
if(s1<s2)
    cout<<-1;
  else
    if(s1==s2)
      cout<<0;
    if(s1>s2)
      cout<<1;
} 
相关文章
|
XML 存储 开发工具
|
缓存 安全 Java
Java反射常见面试题最新总结
Java反射常见面试题总结
495 0
|
人工智能 IDE 程序员
通义灵码:AI 研发趋势与效果提升实践丨SDCon 全球软件技术大会演讲全文整理
SDCon 全球软件技术大会上,阿里云通义灵码团队分享了关于 AI 辅助编码的最新研究与实践,随着 AIGC 技术的发展,软件研发领域将迎来智能化的新高度,助力 DevOps 流程优化,提升研发效率和研发幸福感。
14127 11
|
Linux 数据安全/隐私保护
debian使用桌面管理器管理多个桌面系统
在Debian 12中,初始安装了带KDE桌面的系统,KDE自带SDDM显示管理器。为切换桌面,安装了XFCE:`sudo apt install xfce4`。选择SDDM登录后点击“桌面会话”选XFCE。遇到问题:无法通过SDDM登录root。解决方案包括编辑`pam.d/sddm`和`root/.bashrc`,然后重启SDDM或系统。要彻底卸载XFCE,使用:`sudo apt remove *xfce4*`, `sudo apt autoremove`, `sudo apt clean`,重启后无XFCE选项。
|
iOS开发 MacOS
WAServiceMainContext.js:2 Error: MiniProgramError
WAServiceMainContext.js:2 Error: MiniProgramError
526 0
|
存储 Linux KVM
虚拟化技术之KVM安装与使用
虚拟化技术之KVM安装与使用
|
移动开发 前端开发 JavaScript
web前端基础知识——HTML/HTML5
HTML 是用来描述网页的一种语言。 HTML 指的是超文本标记语言: HyperText Markup Language HTML 不是一种编程语言,而是一种标记语言 标记语言是一套标记标签 (markup tag) HTML 使用标记标签来描述网页 HTML 文档包含了HTML 标签及文本内容 HTML文档也叫做 web 页面
292 2
|
数据可视化 定位技术
【threejs】可视化大屏酷炫3D地图附源码
【threejs】可视化大屏酷炫3D地图附源码
11060 130
【threejs】可视化大屏酷炫3D地图附源码
|
存储 SQL JSON
大分区表高并发性能提升100倍?阿里云 RDS PostgreSQL 12 特性解读
世界上几乎最强大的开源数据库系统 PostgreSQL,于 2019 年 10 月 3 日发布了 12 版本,该版本已经在阿里云正式发布。PostgreSQL 12 在功能和性能上都有很大提升,如大分区表高并发性能提升百倍,B-tree 索引空间和性能优化,实现 SQL 2016 标准的 JSON 特性,支持多列 MCV(Most-Common-Value)统计,内联 CTE(Common table expressions)以及可插拔的表存储访问接口等。本文对部分特性进行解读。
3574 0
大分区表高并发性能提升100倍?阿里云 RDS PostgreSQL 12 特性解读
|
缓存 负载均衡 Java
Nginx负载均衡配置教程-Linux
Nginx负载均衡配置教程-Linux
457 0