※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 27329번 문제인 繰り返し文字列 (Repeating String)이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/27329 

 

27329번: 繰り返し文字列 (Repeating String)

IOIOIO は同じ文字列を 2 つつなげて得ることはできないので,繰り返し文字列ではない.よって No を出力する.

www.acmicpc.net

주어지는 문자열의 앞 절반과 뒤 절반이 같은지를 확인하는 문제이다.

 

문자열의 substr 메소드를 이용하면 문제를 해결하는 코드를 간단하게 작성할 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;

int slen;
string s;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> slen >> s;
	if (s.substr(0, slen / 2) == s.substr(slen / 2, slen / 2)) cout << "Yes";
	else cout << "No";
}
728x90

+ Recent posts