hdu2816I Love You Too

#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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值