当前位置:网站首页>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;
}
边栏推荐
- Leetcode bit operation
- 20220531 Mathematics: Happy numbers
- Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
- Deep learning by Pytorch
- Tensorflow2.0 save model
- . DLL and Differences between lib files
- 20220601 Mathematics: zero after factorial
- 20220607 others: sum of two integers
- QT setting suspension button
- Connect Alibaba cloud servers in the form of key pairs
猜你喜欢

CV learning notes - deep learning

Development of intelligent charging pile (I): overview of the overall design of the system

使用密钥对的形式连接阿里云服务器

LeetCode - 715. Range module (TreeSet)*****

Opencv feature extraction - hog

Leetcode 300 最长上升子序列
![Step 1: teach you to trace the IP address of [phishing email]](/img/a5/c30bc51da560c4da7fc15f434dd384.png)
Step 1: teach you to trace the IP address of [phishing email]

My notes on intelligent charging pile development (II): overview of system hardware circuit design

CV learning notes - scale invariant feature transformation (SIFT)

Neural Network Fundamentals (1)
随机推荐
Step 1: teach you to trace the IP address of [phishing email]
CV learning notes - deep learning
Label Semantic Aware Pre-training for Few-shot Text Classification
Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
Positive and negative sample division and architecture understanding in image classification and target detection
LeetCode - 1670 設計前中後隊列(設計 - 兩個雙端隊列)
CV learning notes - feature extraction
QT setting suspension button
Swing transformer details-1
QT self drawing button with bubbles
20220610 other: Task Scheduler
Leetcode-100: same tree
Leetcode 300 longest ascending subsequence
Deep learning by Pytorch
Wireshark use
LeetCode - 933 最近的请求次数
20220608 other: evaluation of inverse Polish expression
My notes on intelligent charging pile development (II): overview of system hardware circuit design
【C 题集】of Ⅵ
1. Finite Markov Decision Process