小书童——密码

题目背景
某蒟蒻迷上了“小书童”,有一天登陆时忘记密码了(他没绑定邮箱or手机),于是便把问题抛给了神犇你。

题目描述
蒟蒻虽然忘记密码,但他还记得密码是由一个字符串组成。密码是由原文字符串(由不超过 50 个小写字母组成)中每个字母向后移动 n位形成的。z 的下一个字母是 a,如此循环。他现在找到了移动前的原文字符串及 n,请你求出密码。

输入格式
第一行:n。第二行:未移动前的一串字母

输出格式
一行,是此蒟蒻的密码

输入输出样例
输入 #1

1
qwe
输出 #1
rxf
说明/提示
字符串长度<=50

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int ff[26];//定义计数数组
int main()
{
	string s;
	int n,i,j;
	cin>>n;
	cin>>s;
	for(i=0;i<s.size();++i)
	{
		for(j=1;j<=n;++j)
		{
			++s[i];
			if(s[i]>'z')
				s[i]='a';
		}
	}
	cout<<s;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Python编写的一个图灵机,它会输出字符串“hello,world”: ```python tape = [0] * 1000 # 初始化磁带,长度为1000 head = len(tape) // 2 # 初始化磁头的位置 program = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." # 程序 pc = 0 # 程序计数器 while pc < len(program): instr = program[pc] if instr == '>': # 将磁头向右移动 head += 1 elif instr == '<': # 将磁头向左移动 head -= 1 elif instr == '+': # 将磁带上的值加1 tape[head] += 1 elif instr == '-': # 将磁带上的值减1 tape[head] -= 1 elif instr == '.': # 输出磁带上的值 print(chr(tape[head]), end="") elif instr == ',': # 从输入中读取一个字符并存储到磁带上 tape[head] = ord(input()) elif instr == '[': # 如果磁带上的值为0,则跳转到对应的']'指令后面 if tape[head] == 0: depth = 1 while depth > 0: pc += 1 if program[pc] == '[': depth += 1 elif program[pc] == ']': depth -= 1 elif instr == ']': # 如果磁带上的值不为0,则跳转到对应的'['指令面 if tape[head] != 0: depth = 1 while depth > 0: pc -= 1 if program[pc] == ']': depth += 1 elif program[pc] == '[': depth -= 1 pc += 1 ``` 在这个例子中,我们使用了一个长度为1000的列表来表示磁带,用一个变量来表示磁头的位置。程序也是一个字符串。在程序的执行过程中,我们使用了一个while循环来处理不同的指令。在程序中,我们还使用了一个栈来处理循环指令'['和']'。最终,程序会输出字符串“hello,world”。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值