当前位置:网站首页>Inverse code of string (Jilin University postgraduate entrance examination question)
Inverse code of string (Jilin University postgraduate entrance examination question)
2022-07-03 10:19:00 【Innocent^_^】
Topic
A binary number , Reverse every bit of it , It's called the inverse of this number . Let's define the inverse of a character . If this is a lowercase character , Then it and the character ’a’ Distance with its inverse code and character ’z’ The same distance ; If it's an uppercase character , Then it and the character ’A’ Distance with its inverse code and character ’Z’ The same distance ; If it wasn't for the above two situations , Its inverse is itself . Take a few examples ,'a’ The opposite of ’z’;‘c’ The opposite of ’x’;‘W’ The opposite of ’D’;‘1’ It's the inverse of ’1’;’%‘ It's the inverse of ’%’. The inverse of a string is defined as the inverse of all its characters . Our task is to compute the inverse of a given string .
(’%‘ It's the inverse of ’%' The original question is dollar sign , But I can't type it here , Just make an example to show whether the inverse code of the symbol character is itself )
Input description :
Each input line is a string , The string length does not exceed 80 Characters . If the input is only !, End of input , No need to deal with .
Output description :
For each string entered , Output its inverse code , One line per data .
Example 1
Input
Hello
JLU-CCST-2011
!
Output
Svool
QOF-XXHG-2011
What to pay attention to
Input only "!" It means that the characters you enter in this line are only ! Instead of just entering one !
This question is in Chinese string Just do it , Never mind his length limit
Thinking and test code
1. The distance can be calculated directly with similar s[i]-'a’ It means , This subtraction yields two char Between ASCII Code difference , That's distance
2. Only !, You can set one first bool Variable end by true, Then check whether the string is all composed of ! form , If you find something different from ! The characters of . Then put the end Set to false that will do . Then judge end, If it is true End
The code is as follows ( Has passed Niuke network OJ determine )
#include<iostream>
#include<string>
using namespace std;
string letters = "abcdefghijklmnopqrstuvwxyz";// Lowercase letter set
string letters1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";// Capital alphabet
int main() {
while (true) {
string s; bool end = true;
cin >> s;
for (int i = 0; i < s.size(); ++i) {
if (s[i] != '!') end = false;
}
if (end)break;// The string is all ! Out of the loop
for (int i = 0; i < s.size(); ++i) {
if (islower(s[i])) {
int distance = s[i] - 'a';
for (int i1 = 0; i1 < 26; ++i1) {
if (distance == 'z' - letters[i1])
{
s[i] = letters[i1];
}
}
}
if (isupper(s[i])) {
int distance1 = s[i] - 'A';
for (int i2 = 0; i2 < 26; ++i2) {
if (distance1 == 'Z' - letters1[i2])
{
s[i] = letters1[i2];
}
}
}
cout << s[i];
}
cout << endl;// Line break
}
return 0;
}
边栏推荐
- Standard library header file
- Opencv feature extraction - hog
- Basic use and actual combat sharing of crash tool
- LeetCode - 5 最长回文子串
- CV learning notes alexnet
- CV learning notes - deep learning
- 20220531数学:快乐数
- Leetcode-513:找树的左下角值
- After clicking the Save button, you can only click it once
- Leetcode - 895 maximum frequency stack (Design - hash table + priority queue hash table + stack)*
猜你喜欢

The underlying principle of vector

LeetCode - 1670 設計前中後隊列(設計 - 兩個雙端隊列)

LeetCode - 705 设计哈希集合(设计)

Standard library header file

Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*

Vgg16 migration learning source code

Discrete-event system

Dictionary tree prefix tree trie

Opencv notes 17 template matching

CV learning notes - edge extraction
随机推荐
openCV+dlib實現給蒙娜麗莎換臉
『快速入门electron』之实现窗口拖拽
Leetcode - 705 design hash set (Design)
2.2 DP: Value Iteration & Gambler‘s Problem
Wireshark use
Leetcode-404: sum of left leaves
20220531数学:快乐数
One click generate traffic password (exaggerated advertisement title)
2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)
重写波士顿房价预测任务(使用飞桨paddlepaddle)
Label Semantic Aware Pre-training for Few-shot Text Classification
LeetCode - 703 数据流中的第 K 大元素(设计 - 优先队列)
openCV+dlib实现给蒙娜丽莎换脸
Modelcheckpoint auto save model
3.3 Monte Carlo Methods: case study: Blackjack of Policy Improvement of on- & off-policy Evaluation
pycharm 无法引入自定义包
Leetcode-404:左叶子之和
Standard library header file
LeetCode - 673. Number of longest increasing subsequences
20220603数学:Pow(x,n)