本帖最后由 yuxijian2020 于 2021-3-28 00:26 编辑
你这个示例输入和输出,我手算都算不出来YES....#include <stdio.h>
#define bool int
#define true 1
#define false 0
bool EqualString(char a[100], char b[100])
{
if (a[0] == 0 && b[0] == 0)
return true;
else if ((a[0] == 0 && b[0] != 0) || (a[0] != 0 && b[0] == 0) || strlen(a) != strlen(b))
return false;
char hash_a[26];
char hash_b[26];
bool isBreak = false;
memset(hash_a, 0, 26);
memset(hash_b, 0, 26);
for (int i = 0; i < 100; ++i)
{
char temp;
if (a[i] == 'A')
temp = 'Z';
else
temp = a[i] - 1;
hash_a[temp - 0x41]++;
hash_b[b[i] - 0x41]++;
}
for (int i = 0; i < 26; ++i)
{
if (hash_a[i] != hash_b[i])
{
isBreak = true;
break;
}
}
if (!isBreak)
return true;
memset(hash_a, 0, 26);
memset(hash_b, 0, 26);
for (int i = 0; i < 100; ++i)
{
char temp;
if (b[i] == 'A')
temp = 'Z';
else
temp = b[i] - 1;
hash_b[temp - 0x41]++;
hash_a[a[i] - 0x41]++;
}
for (int i = 0; i < 26; ++i)
{
if (hash_a[i] != hash_b[i])
return false;
}
return true;
}
int main()
{
char a[100] = "WJDUPSJPVT";
char b[100] = "VICTORIOUS";
bool flag = EqualString(a, b);
if (flag)
printf_s("YES\n");
else
printf_s("NO\n");
return 0;
}
|