Little_person
Zest9610
2016-05-29 13:29

北大poj 百练 2820:古代密码

真心不知道那种情况没有考虑,我自己试的几组测试没问题啊,很郁闷,一直是WA,请各位大神看看我哪里错了
#include
#include
using namespace std;
bool fun(int *a, int *b,int l){
for (int i = 0; i < l; i++)
{
for (int j = 0; j < l; j++)
{
if (a[i] == b[j])b[j] = -1; break;
}
}
int i;
for ( i = 0; i < l; i++)
{
if (b[i] != -1)break;
}
if (i == l)return 1;
else return 0;
}
int main(){
string a, b;
cin >> a;
cin >> b;
if (a.length() != b.length())
cout << "NO";
else
{
int l = b.length();
int *s1 = new int[l];
int *s2 = new int[l];
for (int i = 0; i < l; i++)
{
s1[i] = b[i] - 64;
s2[i] = a[i] - 64;
}
int N = 25;
while (N--){
for (int i = 0; i < l; i++){
if (s1[i] + 1>26)s1[i] = 1;
else s1[i]++;
}
if (fun(s1, s2, l)){
cout << "YES"; return 1;
}
}
cout << "NO";
return 1;
}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换