P1079 [NOIP2012 提高组] Vigenère 密码
#include<bits/stdc++.h>
using namespace std;
int main()
{
string m,key;
char k;
cin>>m>>key;
for(int i=0;i<m.size();i++)
{
k=key[i%key.size()];
if(k>='A' && k<='Z')
{
if(m[i]>='A' && m[i]<='Z')
{
cout<<char(((m[i]-'A')+(k-'A'))%26);
}
else if(m[i]>='a' && m[i]<='z')
{
cout<<char(((m[i]-'a')+(k-'A'))%26);
}
}
else if(k>='a' && k<='z')
{
if(m[i]>='A' && m[i]<='Z')
{
cout<<char(((m[i]-'A')+(k-'a'))%26);
}else if(m[i]>='a' && m[i]<='z')
{
cout<<char(((m[i]-'a')+(k-'a'))%26);
}
}
}
return 0;
}
求助