显示代码纯文本
/**************************************************************
Problem: cojs1262 Vigenere Pin[NOIP2012 DAY1]
User: hznq60050(cobra)
Solution: Simulation(模拟)
Language: C++
Result: ACCEPT
****************************************************************/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
string a[32];
bool vis[1002];
void reset(void){
a[1]=" azyxwvutsrqponmlkjihgfedc";
a[2]=" bazyxwvutsrqponmlkjihgfed";
a[3]=" cbazyxwvutsrqponmlkjihgfe";
a[4]=" dcbazyxwvutsrqponmlkjihgf";
a[5]=" edcbazyxwvutsrqponmlkjihg";
a[6]=" fedcbazyxwvutsrqponmlkjih";
a[7]=" gfedcbazyxwvutsrqponmlkji";
a[8]=" hgfedcbazyxwvutsrqponmlkj";
a[9]=" ihgfedcbazyxwvutsrqponmlk";
a[10]=" jihgfedcbazyxwvutsrqponml";
a[11]=" kjihgfedcbazyxwvutsrqponm";
a[12]=" lkjihgfedcbazyxwvutsrqpon";
a[13]=" mlkjihgfedcbazyxwvutsrqpo";
a[14]=" nmlkjihgfedcbazyxwvutsrqp";
a[15]=" onmlkjihgfedcbazyxwvutsrq";
a[16]=" ponmlkjihgfedcbazyxwvutsr";
a[17]=" qponmlkjihgfedcbazyxwvuts";
a[18]=" rqponmlkjihgfedcbazyxwvut";
a[19]=" srqponmlkjihgfedcbazyxwvu";
a[20]=" tsrqponmlkjihgfedcbazyxwv";
a[21]=" utsrqponmlkjihgfedcbazyxw";
a[22]=" vutsrqponmlkjihgfedcbazyx";
a[23]=" wvutsrqponmlkjihgfedcbazy";
a[24]=" xwvutsrqponmlkjihgfedcbaz";
a[25]=" yxwvutsrqponmlkjihgfedcba";
a[26]=" zyxwvutsrqponmlkjihgfedcb";
return ;
}
char work(int i,char c,char cc)
{
char ch;
int c1=(int)c-96;
int c2=(int)cc-96;
ch=a[c1][c2];
if(vis[i])
ch-=32;
return ch;
}
int main()
{
freopen("vigenere.in","r",stdin);
freopen("vigenere.out","w",stdout);
reset();
string key,mi;
cin>>key>>mi;
int lenk=key.size();
for(int i=0;i<=lenk-1;i++)
if(key[i]>=65&&key[i]<97)
key[i]+=32;
for(int i=0;i<=mi.size()-1;i++)
if(mi[i]>=65&&mi[i]<97)
{
mi[i]+=32;
vis[i+1]=1;
}
key=' '+key;
int lenmi=mi.size();
mi=' '+mi;
for(int i=1;i<=lenmi;i++)
{
int pos=i%lenk;
if(!pos)
pos=lenk;
cout<<work(i,mi[i],key[pos]);
}
}
/*
abc
Hfnlpyosnd*/