信息学作业,改了2小时了
改半天本地运行还是错两个字母 第一次做 普及- 的题
#include <bits/stdc++.h>
using namespace std;
int main (){
//处理k
int lengthK,lengthC,pip,d;
string k,c,kresize,kjia;
cin>>k;
cin>>c;
lengthK = k.length();
lengthC = c.length();
if(lengthK>lengthC){
k.resize(lengthC);
}else if(lengthK==lengthC){
}else{
pip=lengthC/lengthK;
d=lengthC%lengthK;
kjia=k;
for(int i=1;i<=pip-1;i++){
k+=kjia;
}
if(d!=0){
kresize=k;
kresize.resize(d);
k+=kresize;
}
}
//处理k结束
for(int j=0;j<lengthC;j++){
if(int(c[j])<=90 && int(c[j])>=65){//ifc[j]大写
if(int(k[j])<=90 && int(k[j])>=65){//ifk[j]大写
c[j]=char(int(c[j])-(int(k[j]-65)));
}
else if(int(k[j])<=122 && int(k[j])>=97){//ifk[j]小写
c[j]=char(int(c[j])-(int(k[j]-97)));
}else{
}
}else if(int(c[j])<=122 && int(c[j])>=97){//ifc[j]小写
if(int(k[j])<=90 && int(k[j])>=65){//ifk[j]大写
c[j]=char(int(c[j])-(int(k[j]-65)));
}
else if(int(k[j])<=122 && int(k[j])>=97){//ifk[j]小写
if(char(int(c[j])-(int(k[j]-97)))<97){
c[j]=char(int(c[j])-(int(k[j]-97))+26);
}else{
c[j]=char(int(c[j])-(int(k[j]-97)));
}
}else{
}
}
}
cout<<c;
return 0;
}
输入:
CompleteVictory
Yvqgpxaimmklongnzfwpvxmniytm
输出:
WheretheXeisawillthereiYaway
正确输出:
Wherethereisawillthereisaway
我的代码过一个小时自己就看不懂了……