当前位置:网站首页>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;
}
边栏推荐
- One click generate traffic password (exaggerated advertisement title)
- Toolbutton property settings
- Label Semantic Aware Pre-training for Few-shot Text Classification
- Leetcode - the k-th element in 703 data flow (design priority queue)
- Opencv feature extraction - hog
- Leetcode 300 最长上升子序列
- Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)
- My notes on the development of intelligent charging pile (III): overview of the overall design of the system software
- 20220602 Mathematics: Excel table column serial number
- LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
猜你喜欢
Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:
Label Semantic Aware Pre-training for Few-shot Text Classification
LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))
Opencv notes 20 PCA
Label Semantic Aware Pre-training for Few-shot Text Classification
Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
Boston house price forecast (tensorflow2.9 practice)
Opencv gray histogram, histogram specification
Leetcode - 1172 plate stack (Design - list + small top pile + stack))
QT self drawing button with bubbles
随机推荐
Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
Leetcode-100: same tree
openCV+dlib实现给蒙娜丽莎换脸
LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
2.1 Dynamic programming and case study: Jack‘s car rental
My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
Label Semantic Aware Pre-training for Few-shot Text Classification
LeetCode - 673. 最长递增子序列的个数
Opencv histogram equalization
Opencv interview guide
Wireshark use
Leetcode - the k-th element in 703 data flow (design priority queue)
Swing transformer details-1
20220609 other: most elements
My notes on intelligent charging pile development (II): overview of system hardware circuit design
CV learning notes - image filter
LeetCode - 1670 设计前中后队列(设计 - 两个双端队列)
Deep Reinforcement learning with PyTorch
20220602 Mathematics: Excel table column serial number
使用密钥对的形式连接阿里云服务器