#include <iostream>
#include <map>
using namespace std;
#define NSIZ 1010
char str[NSIZ];
char source[27] = {"QWERTYUIOPASDFGHJKLZXCVBNM"};
char target[27] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
typedef struct Node_
{
int key;
char value[5];
}Node;
Node dic[20];
map<char, char> Hash;
void Init()
{
dic[0].key = 1;
dic[0].value[1] = '+';
dic[1].key = 1;
dic[1].value[1] = '_';
dic[2].key = 2;
dic[2].value[1] = 'A';
dic[2].value[2] = 'B';
dic[2].value[3] = 'C';
dic[3].key = 3;
dic[3].value[1] = 'D';
dic[3].value[2] = 'E';
dic[3].value[3] = 'F';
dic[4].key = 4;
dic[4].value[1] = 'G';
dic[4].value[2] = 'H';
dic[4].value[3] = 'I';
dic[5].key = 5;
dic[5].value[1] = 'J';
dic[5].value[2] = 'K';
dic[5].value[3] = 'L';
dic[6].key = 6;
dic[6].value[1] = 'M';
dic[6].value[2] = 'N';
dic[6].value[3] = 'O';
dic[7].key = 7;
dic[7].value[1] = 'P';
dic[7].value[2] = 'Q';
dic[7].value[3] = 'R';
dic[7].value[4] = 'S';
dic[8].key = 8;
dic[8].value[1] = 'T';
dic[8].value[2] = 'U';
dic[8].value[3] = 'V';
dic[9].key = 9;
dic[9].value[1] = 'W';
dic[9].value[2] = 'X';
dic[9].value[3] = 'Y';
dic[9].value[4] = 'Z';
for (int i = 0;i < 27; ++i)
{
Hash[source[i]] = target[i];
}
}
void Reverse(char * s, char * e)
{
if (!s || !e)
{
return;
}
char tmp;
while(s < e)
{
tmp = *s;
*s = *e;
*e = tmp;
++s;
--e;
}
}
void Divide(char * s)
{
if (!s || *s == 0)
{
return;
}
char t[NSIZ] = {0};
int n = strlen(s);
int half = 0;
int i = 0, j = 0, k = 0;
if (n%2 == 0)
{
half = n / 2 ;
}
else
{
half = n /2 + 1;
}
for (i = 0, j = half; i < half && j < n;)
{
t[k++] = s[i++];
t[k++] = s[j++];
}
if (i < half)
{
t[k++] = s[i++];
}
strcpy(s, t);
}
//Hash
void Decrypt(char * s, int n)
{
if (!s || *s == 0)
{
return;
}
int i = 0;
for (;i < n; ++i)
{
s[i] =Hash[s[i]];
}
}
void ConvertToString(char *s, char *t, int n)
{
if (!s || *s == 0)
{
return;
}
int i = 0;
int j = 0;
for (i = 0;i < n; i += 2)
{
t[j++] = dic[s[i] - '0'].value[s[i+1] - '0'];
}
}
void DecrptProcess(char * s)
{
char t[NSIZ] = {0};
int n = strlen(s);
ConvertToString(s,t,n);
n = strlen(t);
Decrypt(t, n);
Divide(t);
Reverse(t, t + n - 1);
printf("%s\n", t);
}
int main()
{
int t;
Init();
while(scanf("%s", str) != EOF)
{
DecrptProcess(str);
}
return 0;
}
hdu2816I Love You Too
最新推荐文章于 2015-09-01 11:16:05 发布