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

ACM/ICPC ZOJ1006-Do the Untwist 解题代码

2013-07-08 20:15 260 查看
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
string array[30][2];
string a,b;
int t=0;
while( cin >> a )
{
if ( a == "0" )
{
break;
}
else
{
cin >> b;
}
array[t][0] = a;
array[t][1] = b;
t++;
}

for ( int i = 0; i < t; i++ )
{
const char *p = array[i][0].c_str();
int k = atoi(p);
int len = array[i][1].size();
int *ciphercode = new int[len];
for ( int s = 0; s <len; s++ )
{
if ( array[i][1][s] == '.')
{
ciphercode[s] = 27;
}
else if ( array[i][1][s] == '_')
{
ciphercode[s] = 0;
}
else
{
ciphercode[s] = array[i][1][s] - 96;
}
}

int *plaincode = new int[len];
for ( int s = 0; s < len; s++ )
{
int pt = ( k*s )%len;
plaincode[pt] = (ciphercode[s] + s)%28;

//cout <<pt <<" "<< plaincode[pt] << " ";
}
//cout << endl;

char *plaintext = new char[len];
//cout << plaintext << endl;
for ( int s = 0; s < len; s++ )
{
if (plaincode[s] == 0 )
{
plaintext[s] = '_';
}
else if (plaincode[s] == 27 )
{
plaintext[s] = '.';
}
else
{
plaintext[s] = plaincode[s] + 96;
}
}
//string resut(plaintext);
for ( int m = 0; m < len; m++ )
{
cout << plaintext[m];
}
cout << endl;
delete [] plaincode;
delete [] plaintext;
delete [] ciphercode;
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: