题解:AT_joi2023_yo1b_c 繰り返し文字列 (Repeating String)
__Accepted_cyx__ · · 题解
思路
设字符串
则若要满足前一半等于后一半,需要依次对比
-
S_0$ 是否等于 $S_{n\div 2} -
S_1$ 是否等于 $S_{n\div 2 +1} -
S_2$ 是否等于 $S_{n\div 2 +2} -
...
-
S_{n\div 2 -1}$ 是否等于 $S_n
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string S;
cin >> n >> S;
bool res = true;
for (int i = 0; i < n/2; i++) {
if (S[i] != S[i+n/2]) res = false;
}
if (res) cout << "Yes";
else cout << "No";
}