求指正!!!
字符串加密
http://www.nowcoder.com/questionTerminal/e4af1fe682b54459b2a211df91a91cf3
自己ide跑无问题,与对应输出一致,但是测评显示有错
用例:
qrwevoifsrnaxhsuc
epvjrscrnsflxxzchappqjc
对应输出应该为:
vbmngjwgujoxttzwfqbbdnw
你的输出为:
anuhqrfqlrbjxxzfewnnphf
代码:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int flag[28]={0};
string key;
string data;
while (cin >> key)
{
cin >> data;
string tmp = "";
for (int i = 0; i < key.size(); i++)
{
char c = toupper(key[i]);
if (!flag[c - 'A'])
{
tmp += c;
flag[c - 'A'] = 1;
}
}
//生成映射表,A-Z按照顺序如果不在tmp里面那就加载后面
for (int i = 'A'; i <= 'Z'; i++)
{
if (tmp.find(i) == string::npos)
{
tmp += i;
}
}
//处理data
string ans = "";
for (int i = 0; i < data.size(); i++)
{
if (isupper(data[i]))
{
ans += tmp[data[i] - 'A'];
}
else {
char d = toupper(data[i]);
ans += tolower(tmp[d - 'A']);
}
}
cout << ans << endl;
}
return 0;
}
查看10道真题和解析