当前位置:网站首页>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;
}
边栏推荐
- Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly
- 【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
- How to get started and improve test development?
- Dell筆記本周期性閃屏故障
- C Primer Plus Chapter 14 (structure and other data forms)
- Set (generic & list & Set & custom sort)
- 深度学习之环境配置 jupyter notebook
- Advanced learning of MySQL -- basics -- multi table query -- inner join
- C9高校,博士生一作发Nature!
- 浅谈测试开发怎么入门,如何提升?
猜你喜欢

【JVM调优实战100例】05——方法区调优实战(下)

ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版
做微服务研发工程师的一年来的总结

Set (generic & list & Set & custom sort)

Make a simple graphical interface with Tkinter

Provincial and urban level three coordinate boundary data CSV to JSON

Part IV: STM32 interrupt control programming

pyflink的安装和测试

【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)

ZYNQ移植uCOSIII
随机推荐
Explain in detail the implementation of call, apply and bind in JS (source code implementation)
用tkinter做一个简单图形界面
[software reverse automation] complete collection of reverse tools
[牛客] [NOIP2015]跳石头
fastDFS数据迁移操作记录
mongodb客户端操作(MongoRepository)
【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
动态规划思想《从入门到放弃》
Levels - UE5中的暴雨效果
How do novices get started and learn PostgreSQL?
深度学习简史(一)
界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
Configuring the stub area of OSPF for Huawei devices
C9 colleges and universities, doctoral students make a statement of nature!
stm32F407-------DAC数模转换
【JVM调优实战100例】04——方法区调优实战(上)
Trace tool for MySQL further implementation plan
Dell Notebook Periodic Flash Screen Fault
pyflink的安装和测试
Three methods to realize JS asynchronous loading