Codeforces Round #313(Div.2)-D귀속,stirng-Equivalent Strings
2972 단어 codeforces
As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.
Gerald has already completed this home task. Now it's your turn!
Input
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and consists of lowercase English letters. The strings have the same length.
Output
Print "YES"(without the quotes), if these two strings are equivalent, and "NO"(without the quotes) otherwise.
Sample test(s)
input
aaba
abaa
output
YES
input
aabb
abab
output
NO
Note
In the first sample you should split the first string into strings "aa"and "ba", the second one — into strings "ab"and "aa". "aa"is equivalent to "aa"; "ab"is equivalent to "ba"as "ab"= "a"+ "b", "ba"= "b"+ "a".
In the second sample the first string can be splitted into strings "aa"and "bb", that are equivalent only to themselves. That's why string "aabb"is equivalent only to itself and to string "bbaa".
/*
, s1,s2, , if , flag1,
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = 200000 + 10;
char s1[MAX], s2[MAX];
bool isequal(char *ss1, char *ss2, int len)
{
int flag1 = true;
for(int i = 0 ; i < len; i++){
if(ss1[i] != ss2[i]) flag1 = false;
}
if(len % 2 == 1) return flag1;
if((isequal(ss1, ss2, len/2) && isequal(ss1 + len/2, ss2 + len/2, len/2)) || (isequal(ss1, ss2 + len/2, len/2) && isequal(ss1 + len/2, ss2, len/2)))
return true;
}
int main()
{
while(~scanf("%s%s", s1, s2)){
int n = strlen(s1);
int flag = 0;
if(n % 2){
if(strcmp(s1, s2) == 0)
flag = 1;
}
else {
if(strcmp(s1, s2) == 0)
flag = 1;
if(isequal(s1, s2 , n) == 1)
flag = 1;
}
if(flag == 0)
printf("NO
");
else printf("YES
");
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.