当前位置:网站首页>Openjudge noi 1.7 10: simple password
Openjudge noi 1.7 10: simple password
2022-07-07 01:02:00 【Jun Yi_ noip】
【 Topic link 】
OpenJudge NOI 1.7 10: Simple code
【 Topic test site 】
1. ASCII code
2. character string
【 Their thinking 】
We can know by analyzing the law , The plaintext letter is the first number of ciphertext characters 5 Letters .
solution 1: Letters correspond to numbers
Put the letters c Turn to the corresponding number ,A Corresponding number 0,B Corresponding number 1… Z Corresponding number 25, Method is c - 'A'
- If
c - 'A' >= 5
, Then the number corresponding to the plaintext letter isc - 'A' - 5
- If
c - 'A' < 5
, Then the number corresponding to the plaintext letter isc - 'A' + 26 - 5
Last , Then turn numbers into characters
Finally integrated intoc = (c - 'A' + 26 - 5) % 26 + 'A'
solution 2: Directly judge the current letter ASCII code
If the current ciphertext alphabet variable c yes ’E’ And ’E’ The previous letter , Then the corresponding plaintext letter is c+21
If the current ciphertext alphabet variable c yes ’F’ And ’F‘ The letter after , Then the corresponding plaintext letter is c-5
【 Solution code 】
solution 1: A character array Letters correspond to numbers
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[205];
cin.getline(s, 205);
int len = strlen(s);
for(int i = 0; i < len; ++i)
{
if(s[i] >= 'A' && s[i] <= 'Z')
s[i] = (s[i] - 'A' + 26 - 5) % 26 + 'A';
}
cout << s;
return 0;
}
solution 2:string class Judge the character ASCII code
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
getline(cin, s);
for(int i = 0; i < s.length(); ++i)
{
if(s[i] >= 'A' && s[i] <= 'E')
s[i] = s[i] + 21;
else if(s[i] >= 'F' && s[i] <= 'Z')
s[i] = s[i] - 5;
}
cout << s;
return 0;
}
solution 3: Keep reading in characters , Judge output
#include<bits/stdc++.h>
using namespace std;
int main()
{
char c;
c = getchar();
while(c != '\n')
{
if (c >= 'A' && c <= 'Z')
putchar((c - 'A' - 5 + 26) % 26 + 'A');
else
putchar(c);
c = getchar();
}
return 0;
}
边栏推荐
- BFS realizes breadth first traversal of adjacency matrix (with examples)
- Meet the level 3 requirements of ISO 2.0 with the level B construction standard of computer room | hybrid cloud infrastructure
- 《安富莱嵌入式周报》第272期:2022.06.27--2022.07.03
- 第四篇,STM32中断控制编程
- A brief history of deep learning (II)
- 浅谈测试开发怎么入门,如何提升?
- OSPF configuration command of Huawei equipment
- Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
- Part 7: STM32 serial communication programming
- Interface (interface related meaning, different abstract classes, interface callback)
猜你喜欢
C9 colleges and universities, doctoral students make a statement of nature!
Chapter II proxy and cookies of urllib Library
Stm32f407 ------- SPI communication
JS+SVG爱心扩散动画js特效
深入探索编译插桩技术(四、ASM 探秘)
学习使用代码生成美观的接口文档!!!
[Niuke classic question 01] bit operation
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
重上吹麻滩——段芝堂创始人翟立冬游记
[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
随机推荐
[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
STM32开发资料链接分享
城联优品入股浩柏国际进军国际资本市场,已完成第一步
. Bytecode structure of class file
Chapter 5 DML data operation
Leetcode (547) - number of provinces
Linear algebra of deep learning
【JokerのZYNQ7020】AXI_ EMC。
Advantages and disadvantages of code cloning
新手如何入门学习PostgreSQL?
New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
深度学习之环境配置 jupyter notebook
[牛客] B-完全平方数
迈动互联中标北京人寿保险,助推客户提升品牌价值
Learn to use code to generate beautiful interface documents!!!
深入探索编译插桩技术(四、ASM 探秘)
Leetcode(547)——省份数量
[user defined type] structure, union, enumeration
Part V: STM32 system timer and general timer programming
Slow database query optimization