【求助】一、三和五点WA了

好不容易编出来的程序,结果一点、三点和五点都WA了······
c++
#include <array>
#include <cstring>
#include <iostream>
#include <string>
using std::array;
using std::string;
string judge(string, string, string, int);
string decodeOne(string);
string encodeTwo(string, int, int);
string encodeThree(string, int, int);
char encodedCharTwo[10001];
char encodedCharThree[10001];
array<string, 7> result;
int main(void)
{
using std::cin;
using std::cout;
using std::endl;
int i, howManyWord;
string str1, str2, str3;
cin >> howManyWord;
cin.get();
getline(cin, str1);
getline(cin, str2);
getline(cin, str3);
result[0] = judge(str1, str2, str3, howManyWord);
result[1] = judge(str1, str3, str2, howManyWord);
result[2] = judge(str2, str1, str3, howManyWord);
result[3] = judge(str2, str3, str1, howManyWord);
result[4] = judge(str3, str1, str2, howManyWord);
result[5] = judge(str3, str2, str1, howManyWord);
for (i = 0; i < 6; i++)
{
if ("NONE" == result.at(i))
{
continue;
}
else
{
cout << result.at(i) << endl;
}
}
cin.get();
return 0;
}
string judge(string str1, string str2, string str3, int howManyWord)
{
using std::cout;
using std::endl;
int i;
string encodeStr2, encodeStr3, rawStr;
if (0 == howManyWord)
{
return "";
}
rawStr = decodeOne(str1);
for (i = 0; i < 7; i++)
{
encodeStr2 = encodeTwo(rawStr, i, howManyWord);
encodeStr3 = encodeThree(rawStr, i, howManyWord);
if (encodeStr2 != str2 || encodeStr3 != str3)
{
continue;
}
else
{
return rawStr;
}
}
return "NONE";
}
string decodeOne(string str)
{
using std::cout;
using std::endl;
const int LENGTH = str.length();
char tmpChar;
int i, j;
string decodedStr;
decodedStr = str;
for (i = 0, j = LENGTH - 1; i < j; i++, j--)
{
tmpChar = decodedStr.at(i);
decodedStr[i] = decodedStr.at(j);
decodedStr[j] = tmpChar;
}
return decodedStr;
}
string encodeTwo(string rawStr, int k, int howManyWord)
{
using std::strcpy;
int i;
string encodedStr;
strcpy(encodedCharTwo, rawStr.c_str());
for (i = 0; i < howManyWord; i++)
{
encodedCharTwo[i] += k;
if (int(encodedCharTwo[i]) > int('z'))
{
encodedCharTwo[i] = char(int(encodedCharTwo[i]) - int('z') + int('a') - 1);
}
}
encodedStr = encodedCharTwo;
return encodedStr;
}
string encodeThree(string rawStr, int k, int howManyWord)
{
using std::strcpy;
int i;
string encodedStr;
strcpy(encodedCharThree, rawStr.c_str());
for (i = 0; i < howManyWord; i++)
{
encodedCharThree[i] -= k;
if (int(encodedCharThree[i]) < int('a'))
{
encodedCharThree[i] = char(int('z') - int('a') + int(encodedCharThree[i]) + 1);
}
}
encodedStr = encodedCharThree;
return encodedStr;
}

怎么办?求助求助!

1 条评论

  • @ 2018-08-10 20:22:16

    你的代码太不简洁了,看都看不下去

  • 1

信息

ID
1449
难度
6
分类
字符串 | 模拟 点击显示
标签
递交数
6975
已通过
1869
通过率
27%
被复制
9
上传者