当前位置:网站首页>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 - 895 maximum frequency stack (Design - hash table + priority queue hash table + stack)*
- CV learning notes - camera model (Euclidean transformation and affine transformation)
- LeetCode - 715. Range 模块(TreeSet) *****
- Opencv Harris corner detection
- 20220602 Mathematics: Excel table column serial number
- On the problem of reference assignment to reference
- Leetcode-100:相同的树
- Leetcode-106:根据中后序遍历序列构造二叉树
- 20220605数学:两数相除
- RESNET code details
猜你喜欢

Anaconda安装包 报错packagesNotFoundError: The following packages are not available from current channels:

1. Finite Markov Decision Process

LeetCode - 1670 设计前中后队列(设计 - 两个双端队列)

Leetcode 300 longest ascending subsequence

LeetCode - 715. Range 模块(TreeSet) *****

LeetCode - 673. Number of longest increasing subsequences

Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:

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

CV learning notes - Stereo Vision (point cloud model, spin image, 3D reconstruction)

3.1 Monte Carlo Methods & case study: Blackjack of on-Policy Evaluation
随机推荐
LeetCode - 715. Range module (TreeSet)*****
Modelcheckpoint auto save model
[graduation season] the picture is rich, and frugality is easy; Never forget chaos and danger in peace.
20220604数学:x的平方根
LeetCode - 933 最近的请求次数
Rewrite Boston house price forecast task (using paddlepaddlepaddle)
Leetcode 300 longest ascending subsequence
LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
Flutter 退出当前操作二次确认怎么做才更优雅?
CV learning notes - reasoning and training
[C question set] of Ⅵ
Leetcode - the k-th element in 703 data flow (design priority queue)
Leetcode-106:根据中后序遍历序列构造二叉树
Opencv gray histogram, histogram specification
20220605 Mathematics: divide two numbers
LeetCode - 1670 設計前中後隊列(設計 - 兩個雙端隊列)
4.1 Temporal Differential of one step
20220610 other: Task Scheduler
Policy gradient Method of Deep Reinforcement learning (Part One)
CV learning notes - feature extraction