关于一些初级ACM竞赛题目的分析和题解(五)。

拓展了一些字母变换的题目,看题:

131A. cAPS lOCK
time limit per test

0.5 second

memory limit per test

256 megabytes

input

standard input

output

standard output

wHAT DO WE NEED cAPS LOCK FOR?

Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.

Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:

  • either it only contains uppercase letters;
  • or all letters except for the first one are uppercase.

In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.

Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.

Input

The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.

Output

Print the result of the given word's processing.

Examples
input
cAPS

output
Caps

input
Lock

output
Lock

题目理解起来略有难度,n个字母属于【1,100】,满足以下条件之一

1.字母全为大写;2.除了第一个字母外其余全为大写。

时变换大小写,不满足时照常输出,下面是代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{char a[600];   //定义字符串,并确定范围大于100scanf("%s",a);  //输入字符串int b=32;  //  定义变量for(int i=1;a[i];i++)  //  确定条件if(a[i]>='a') b=0;  //执行for(int i=0;a[i];i++)putchar(b^a[i]);  //改变字符串return 0;}

题目涉及到了位与,位或,位异或,的数据处理,举个例子

&= 是按位与之后赋值,^=是按位异或之后赋值,|=是按位或之后赋值。与,或以及异或的操作很简单:

1
2
3
4
  101010         101010        101010
& 011100       | 011100      ^ 011100
---------     ----------    ----------
  001000         111110        110110

先把二进制形式写出来, &表示上下相同的输出该值,|表示上下不同的输出1,^表示上下不同的变为1,相同的统统变为0,这便是原理,

A. HQ9+
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

HQ9+ is a joke programming language which has only four one-character instructions:

  • "H" prints "Hello, World!",
  • "Q" prints the source code of the program itself,
  • "9" prints the lyrics of "99 Bottles of Beer" song,
  • "+" increments the value stored in the internal accumulator.

Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.

You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.

Input

The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.

Output

Output "YES", if executing the program will produce any output, and "NO" otherwise.

Examples
input
Hi!

output
YES

input
Codeforces

output
NO

Note

In the first case the program contains only one instruction — "H", which prints "Hello, World!".

In the second case none of the program characters are language instructions.

本题需要注意细节HQ9+只有HQ9三个字符出现时才会打印 如果出现其中的字母则输出YES

若没有三个字母之一则输出NO,下面是代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{int a,b,l;a=0;b=0;char s[500];  //  定义字符串,并确定范围。scanf("%s",s);  //  输入字符串l=strlen(s);  //  确定字符串长度for (int i=0;i<=l-1;i++){if (s[i]=='H'||s[i]=='Q'||s[i]=='9')  //  判断return 0*printf("YES");  //  执行并输出else b++;}if (b==l)printf("NO");  //  输出
}

有一些细节 例如l=strlen(s) 代表的是s字符串的长度  strlen() 代表字符串长度的函数,

return 0*printf(“a”) 意为输出a并结束,相当于输出后面加break,

关于一些初级ACM竞赛题目的分析和题解(五)。相关推荐

  1. 关于一些初级ACM竞赛题目的分析和题解(二)。

    关于一些初级ACM竞赛题目的分析和题解(二). 今天写了关于排序的题  中间有加号的复杂的一行字符   其次还有关于tolower函数的应用, 上题                           ...

  2. 关于一些初级ACM竞赛题目的分析和题解(十)

    关于一些初级ACM竞赛题目的分析和题解(十) 西面的题目是关于一些字母变换的,上题: A. Word time limit per test 2 seconds memory limit per te ...

  3. 关于一些初级ACM竞赛题目的分析和题解(六)。

    关于一些初级ACM竞赛题目的分析和题解(六). 下面是关于一些关于数字判断的题,比较简单,先来看第一题: A. Lucky Division time limit per test 2 seconds ...

  4. 2019浙江ACM省赛部分题解-ABDEFGHIJK

    太菜了,心态炸了.QAQ A-Vertices in the Pocket() 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  5. 华东交通大学2018年ACM双基程序设计大赛题解

    华东交通大学2018年ACM"双基"程序设计竞赛 代码头多的都是标答Ctrl+c下来的,给自己挖个坟,回头有时间再填回去,不填回去就死在这里吧-- 传送门:https://ac.n ...

  6. ACM新生赛部分题解

    2021级的ACM新生赛已经完结了,我就自己做出来的八道题整理一下题解,因为其他是真的不会. 链接:登录-专业IT笔试面试备考平台_牛客网 来源:牛客网 一.我们是冠军 7 日星期 777 的凌晨,7 ...

  7. 2021暨南大学轩辕杯ACM程序设计新生赛题解

    title : 2021暨南大学轩辕杯ACM程序设计新生赛 date : 2021-12-12 tags : ACM,练习记录 author : Linno 题目链接:https://ac.nowco ...

  8. 2018年第十届ACM四川省省赛题解(10 / 11)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2018ACM四川省省赛 题目链接:https://www.oj.swust.edu.cn/probl ...

  9. 华东交通大学2017年ACM双基程序设计大赛题解

    简单题 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submissio ...

  10. ACM程序设计基础(2)题解

    ACM水题二 CodeForces-1A Theatre Square[水题] - 海岛Blog - CSDN博客 AOJ0009 Prime Number[筛选法+前缀和] - 海岛Blog - C ...

最新文章

  1. 遂宁专业计算机学校,遂宁计算机专业中职学校哪家强
  2. [创业经验] 白手起家的艺术
  3. [云炬创业基础笔记]第二章创业者测试22
  4. php extract 变量覆盖,extract变量覆盖
  5. 电脑开机动画_领克的开机画面,你修改了?
  6. android url回调json,【求助】本地页面如何取某个URL返回的json
  7. 【剑指offer】面试题53 - II:0~n-1中缺失的数字(java)
  8. centos 6.8 挂载NTFS移动硬盘
  9. 盘点12个Python数据可视化库,通吃任何领域
  10. 查看计算机桌面隐藏文件夹,电脑怎么查看隐藏文件(隐藏文件夹显示方法)
  11. Elastic-Job介绍
  12. Linux高级命令find,grep,sed,awk
  13. LiveCharts心得
  14. 回收宝只要6499买华为Mate40 Pro还送iPhone 12手机:结果被秒杀!
  15. 字符串操作函数的实现【详解】
  16. [Kali Linux]入门:内网穿透的教程和实战(很适合入门|附图)
  17. 公告丨Dex.top(大力士)上线Opengram (GRAM)
  18. 【服务计算】第十六周实验报告
  19. 如何运用包过滤技术实现个人防火墙
  20. IDEA创建一个JavaWeb项目详细步骤

热门文章

  1. sterm机器人编程_STEAM智能编程机器人
  2. navicat超时未激活如何处理?
  3. Abaqus 子结构分析 实例
  4. Shiro面试题答案
  5. 利用winrar安全加密
  6. python二元函数拟合_Python拟合二元一次函数
  7. layer弹窗内容显示不全的解决方法
  8. 万字教程:Python Word 文档自动化
  9. 人社部《劳动合同》通用范本模板
  10. 【好玩的代码雨(附源代码