3147. 维吉尼亚密码

zzpzbl
[已删除]
celebration

呜呜呜 冷淠太强了 追不上辽TAT

fwx_peter

数论没学好,求余写得太复杂

include

using namespace std;
int main(){
int t;
cin>>t;
getchar();
for (int i=0; i<t; i++) {
string str;
string key;
string answer;
getline(cin, str);
//cout<<str<<endl;
getline(cin, key);
//cout<<key<<endl;
int flag=0;
for (int j=0; j<str.size(); j++) {
if (str[j]==’ ‘) {
answer.insert(j, ” “);
}else{
string temp;
temp=(str[j]+(key[flag%key.size()]-‘A’)-‘A’)%26+’A’;
//cout<<temp;
answer.insert(j, temp);
flag++;
}
}
cout<<”case #”<<i<<”:”<<endl;
cout<<answer<<endl;
}
return 0;
}

Li Dao

供大家参考

include

using namespace std;
int T;
char encode(char aa,char bb)
{
return (aa+bb-‘A’-‘A’)%26+’A’;
}
void solve()
{
string line;
string strs;
getline(cin,line);
getline(cin,line);
cin>>strs;

int pos=0;
int l1=line.length(),l2=strs.length();
for(int i=0;i<l1;i++)
{
if(line[i]==’ ‘) cout<<’ ‘;
else
{
cout<<encode(line[i],strs[pos]);
pos=(pos+1)%l2;
}
}
cout<<endl;
return;
}

int main()
{
scanf(“%d”,&T);
for(int step=0;step<T;step++)
{
printf(“case #%d:\n”,step);
solve();
}
return 0;
}

10175102262 LarsPendragon

用gets会RE,要用fgets

你当前正在回复 博客/题目
存在问题!