您的位置:首页 > 编程语言 > C语言/C++

ZOJ 1006 Do the Untwist

2017-03-15 19:14 330 查看
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <memory.h>
#include <string.h>
#include <stdio.h>

using namespace std;

int main()
{
int key, n;
char plaintext[80], ciphertext[80];
int plaincode[80], ciphercode[80];
map<char, int> MapA;
map<int, char> MapB;
for (char c = 'a'; c <= 'z'; c++)
{
MapA[c] = c - 'a' + 1;
}
MapA['_'] = 0;
MapA['.'] = 27;
for (int i = 1; i < 27; i++)
{
MapB[i] = 'a' + i - 1;
}
MapB[0] = '_';
MapB[27] = '.';
//freopen("d:\\input.txt", "r", stdin);
while (cin >> key)
{
if (key == 0)
{
break;
}
cin >> ciphertext;
n = strlen(ciphertext);
for (int i = 0; i < n; i++)
{
ciphercode[i] = MapA[ciphertext[i]];
}
for (int i = 0; i < n; i++)
{
plaincode[key*i%n] = (ciphercode[i] + i) % 28;
}
for (int i = 0; i < n; i++)
{
plaintext[i] = MapB[plaincode[i]];
}
plaintext
= 0;
cout << plaintext << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Do the Untwist ZOJ C++