ZOJ1006 Do the Untwist
来源:互联网 发布:org.apache.shiro jar 编辑:程序博客网 时间:2024/05/16 07:38
/*===================
From : Zoj1006
Author : zscas08220
Algorithm :
ciphercode[i] = (plaincode[ki mod n] - i) % 28 --->
plaincode[ki % n] = (ciphercode[i]+i) % 28。
===================*/
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
char CC[]="_abcdefghijklmnopqrstuvwxyz.";
char Msg[72];
int k,n,PT[72];
void ToPlainCode()
{
for(int i=0;i<n;i++)
{
switch(Msg[i])
{
case '_':
PT[i]=0;break;
case '.':
PT[i]=27;break;
default:
PT[i]=Msg[i]-'a'+1;
}
}
}
void Decrypt()
{
int i;
int tmp[72];
for(i=0;i<n;i++) tmp[i]=PT[i];
for(i=0;i<n;i++)
{
PT[(k*i)%n]=(tmp[i]+i)%28;
}
}
void ToText()
{
for(int i=0;i<n;i++)
{
Msg[i]=CC[PT[i]];
}
}
int main()
{
while(cin>>k&&k)
{
cin>>Msg;
n=strlen(Msg);
ToPlainCode();
Decrypt();
ToText();
cout<<Msg<<endl;
}
return 0;
}
From : Zoj1006
Author : zscas08220
Algorithm :
ciphercode[i] = (plaincode[ki mod n] - i) % 28 --->
plaincode[ki % n] = (ciphercode[i]+i) % 28。
===================*/
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
char CC[]="_abcdefghijklmnopqrstuvwxyz.";
char Msg[72];
int k,n,PT[72];
void ToPlainCode()
{
for(int i=0;i<n;i++)
{
switch(Msg[i])
{
case '_':
PT[i]=0;break;
case '.':
PT[i]=27;break;
default:
PT[i]=Msg[i]-'a'+1;
}
}
}
void Decrypt()
{
int i;
int tmp[72];
for(i=0;i<n;i++) tmp[i]=PT[i];
for(i=0;i<n;i++)
{
PT[(k*i)%n]=(tmp[i]+i)%28;
}
}
void ToText()
{
for(int i=0;i<n;i++)
{
Msg[i]=CC[PT[i]];
}
}
int main()
{
while(cin>>k&&k)
{
cin>>Msg;
n=strlen(Msg);
ToPlainCode();
Decrypt();
ToText();
cout<<Msg<<endl;
}
return 0;
}
- ZOJ1006 Do the Untwist
- zoj1006-Do the Untwist
- ZOJ1006-Do the Untwist
- Do the Untwist (1006)
- Do the Untwist
- 1006 Do the Untwist
- Do the Untwist
- Do the Untwist
- Do the Untwist
- C++ --Do the Untwist
- POJ1317 Do the Untwist
- Do the Untwist
- 1006 Do the Untwist
- 1006.Do the Untwist
- ACM-1006-Do the Untwist
- ZOJ-1006-Do the Untwist
- HDU 1129 Do the Untwist
- zoj 1006 Do the Untwist
- Hello World!
- android full screen
- LiveCD
- SuSE 10 VNC to MAC OS X
- 新装服务器系统/IIS/数据库问题,请教!
- ZOJ1006 Do the Untwist
- vtkDelaunay3D用法、用途及原理
- linux + mysql笔记
- Ubuntu LiveUSB
- SQL命令大全-中英文对照
- 初探C#3.0
- Love to be loved by you
- 【笑话:】执子之手,方知子丑,泪流满面,子不走我走。爆笑死你我不负责~~~~[
- 介绍两款小巧的Linux发行版:Slax与DSL