64,683
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void)
{
string code, org, tmp;
cin >> code >> org;
sort(org.begin(), org.end());
int f = 0;
for (int j = 1; j <= 25; j++)
{
tmp = code;
for (int i = 0; tmp[i] != '\0'; i++)
{
if (tmp[i] - j < 65)
tmp[i] += 26 - j;
else
tmp[i] -= j;
}
sort(tmp.begin(), tmp.end());
if (org == tmp)
{
cout << "YES" << endl;
f = 1;
break;
}
}
if (f == 0)
cout << "NO" << endl;
return 0;
}
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void)
{
string code, org;
cin >> code >> org;
bool flag = true;
unsigned int i = 0;
int index = 0;
int array[26] = {0};
for (i=0; i<org.size(); i++)
{
// index = (org[i] - 'A' + 1) % 26;
index = ( org[i] == 'Z' ? 0 : (org[i] - 'A' + 1) );
array[index] ++;
}
for (i=0; i<code.size(); i++)
{
index = code[i] - 'A';
array[index] --;
}
for (i=0; i<26; i++)
{
if (array[i] != 0)
{
flag = false;
break;
}
}
if (flag)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return 0;
}
// 测试例子
/*
JWPUDJSTVP
VICTORIOUS
YES
请按任意键继续. . .
*/
#include <stdio.h>
#include <string.h>
void init(int *count)
{
int i;
for (i = 0; i < 26; i++)
count[i] = 0;
}
int isEqual(int* count1, int* count2)
{
int i;
for (i = 0; i < 26; i++)
if (count1[i] != count2[i])
return 0;
return 1;
}
int main(void)
{
int i, j;
int count1[26], count2[26];
char code[101], org[101], tmp[101];
scanf("%s %s", code, org);
init(count1);
for (i = 0; code[i] != '\0'; i++)
++count1[code[i] - 'A'];
for (i = 1; i <= 25; i++)
{
strcpy(tmp, org);
init(count2);
for (j = 0; tmp[j] != '\0'; j++)
{
if (tmp[j] + i > 90)
tmp[j] += i - 26;
else
tmp[j] += i;
count2[tmp[j] - 'A']++;
}
if (isEqual(count1, count2))
{
printf("YES\n");
return 0;
}
}
printf("NO\n");
return 0;
}
#include <iostream>
#include <string>
using namespace std;
void init(int* b)
{
int i;
for (i = 0; i < 26; i++)
b[i] = 0;
}
void count(int* b, string tmp)
{
int i;
for (i = 0; tmp[i] != '\0'; i++)
b[tmp[i] - 'A']++;
}
int compare(int* a, int* b)
{
int i;
for (i = 0; i < 26; i++)
if (a[i] != b[i])
return 1;
return 0;
}
int main(void)
{
int a[26], b[26];
int i, j, f = 0;
string code, org, tmp;
cin >> code >> org;
init(a);
for (i = 0; code[i] != '\0'; i++)
a[code[i] - 'A']++;
for (i = 0; i <= 25; i++)
{
tmp = org;
init(b);
for (j = 0; tmp[j] != '\0'; j++)
{
if (tmp[j] + i > 90)
tmp[j] += i - 26;
else
tmp[j] += i;
}
count(b, tmp);
if (compare(a, b) == 0)
{
cout << "YES" << endl;
f = 1;
break;
}
}
if (f == 0)
cout << "NO" << endl;
return 0;
}