problem 1009
来源:互联网 发布:阿里云服务器数据迁移 编辑:程序博客网 时间:2024/04/28 07:35
题意蛮难懂的。
提醒注意两点:
- 题目要求我们做的是逆向转换!
- 时间限制为十秒,这意味着数据量会比较大,所以数组要开的大一点(我RTE了两次的说)。
Accepted 1009 C++ 00:00.13 396K
#include<stdio.h>
void solve(int m)
{
int i,j,n;
char rotor[3][27];
for(i = 0; i < 3; i++)
{
char temp[27];
scanf("%s",temp);
for(j = 0; j < m; j++)
rotor[i][temp[j] - 'A'] = (j + 'A') - temp[j];
}
scanf("%d",&n);
while(n--)
{
char temp[1000];
scanf("%s",temp);
int p[3] = {0,0,0};
for(i = 0; temp[i]; i++)
{
int r = temp[i] - 'A';
for(j = 2; j >= 0; j--)
r = (rotor[j][(r + p[j]) % m] + r + m) % m;
printf("%c",r + 'a');
p[0] = (p[0] - 1 + m) % m;
if(p[0] == 0)
{
p[1] = (p[1] - 1 + m) % m;
if(p[1] == 0) p[2] = (p[2] - 1 + m) % m;
}
}
printf("/n");
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1009.txt","r",stdin);
#endif
int m,t = 0;
while(scanf("%d",&m) != EOF && m != 0)
{
if(t > 0) printf("/n");
printf("Enigma %d:/n",++t);
solve(m);
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
void solve(int m)
{
int i,j,n;
char rotor[3][27];
for(i = 0; i < 3; i++)
{
char temp[27];
scanf("%s",temp);
for(j = 0; j < m; j++)
rotor[i][temp[j] - 'A'] = (j + 'A') - temp[j];
}
scanf("%d",&n);
while(n--)
{
char temp[1000];
scanf("%s",temp);
int p[3] = {0,0,0};
for(i = 0; temp[i]; i++)
{
int r = temp[i] - 'A';
for(j = 2; j >= 0; j--)
r = (rotor[j][(r + p[j]) % m] + r + m) % m;
printf("%c",r + 'a');
p[0] = (p[0] - 1 + m) % m;
if(p[0] == 0)
{
p[1] = (p[1] - 1 + m) % m;
if(p[1] == 0) p[2] = (p[2] - 1 + m) % m;
}
}
printf("/n");
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1009.txt","r",stdin);
#endif
int m,t = 0;
while(scanf("%d",&m) != EOF && m != 0)
{
if(t > 0) printf("/n");
printf("Enigma %d:/n",++t);
solve(m);
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
- problem 1009
- Problem 1009
- Problem 1009
- 浙江省赛problem 1009
- 1009 Problem I
- problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- problem
- Problem
- Problem
- Problem
- AJAX学习目录
- 网页设计必然趋势:DIV+CSS
- 将闪存改造为系统加密狗
- Ant学习(1)
- php上传文件涉及到的参数
- problem 1009
- 在GridView里使用CheckBox
- iBatisnet Quick Start(转)
- 函数参数地址和返回地址的关系
- asp错误处理机制
- iBatisnet配置(转)
- 命令行运行好处多 操作方法详细讲解
- iBatisnet基本组件(转)
- 测试工作内容1