题目:http://www.tsinsen.com/ViewGProblem.page?gpid=A1366


题目解析:随后
代码:
/*
* =====================================================================================
*
* Filename: Noip2012mima.c
*
* Description: RT
*
* Version: 1.0
* Created: 2014-05-20 14:42:40
* Revision: none
* Compiler: gcc
*
* Author: Rainboy (mn), 597872644@qq.com
* Company: NONE
*
* =====================================================================================
*/
#include <stdio.h>
#include <string.h>
char mimabiao[26][26];
char mishi[100],miwen[1000];
int main(int argc, const char *argv[])
{
//第一步 生成密码表
char a ='A';
int i,j,k,l,mishilength,miwenlength;
for (i = 0; i < 26; i++) //竖行
{
a = 'A'+i;
for (j = 0; j < 26; j++) // 横行
{
mimabiao[i][j] = a;
if(++a > 'Z')
a = 'A';
}
}
//注意 要保持明文中的字母大小写
l=0;//秘钥 现在所在的位置
scanf("%s",mishi);
mishilength =strlen(mishi);
scanf("%s",miwen);
miwenlength = strlen(miwen);
//把秘钥转成 大写
for (i = 0; i < mishilength; i++)
{
mishi[i]=toupper(mishi[i]);
}
for (i = 0; i < miwenlength; i++)
{
if(miwen[i] < 'a')//判断大小写字母 'a' >'A'
for(j = 0; j < 26; j++)
{
if(mimabiao[mishi[l]-'A'][j] == miwen[i])
{
printf("%c",'A'+j);
break;
}
}
else
for(j = 0; j < 26; j++)
if(mimabiao[mishi[l]-'A'][j] == toupper(miwen[i]))
{
printf("%c",'a'+j);
break;
}
if (++l >= mishilength)
{
l=0;
}
}
return 0;
}