
문제
* 해당 문제의 모든 저작권은 SWEA 측에 있으며 본 블로그는 학업 흔적을 남겨 학업 상향을 위한 블로그로 이익을 추구하지 않으며 SWEA 측의 약관을 위배하지 않음을 명시합니다.*
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5P1kNKAl8DFAUq
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
풀이
문자열 비교와 반복문의 범위만 잘 잡아주면 되는 단순 구현이다.
substr 함수를 사용하면 정말 쉽게 풀 수 있다.
소스 코드
// Library
#include <iostream>
#include <string>
#include <stack>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <cctype>
#include <set>
#include <string.h>
#include <string>
// std::
using namespace std;
// Test_case
int T, test_case;
// Value
int N;
// Matrix direction
//int dx[4] = { 0, 0, 1, -1 };
//int dy[4] = { 1, -1, 0, 0 };
// Sturct
//struct st {
//};
// Main function
int main() {
// cin, cout
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// SWEA 양식
// T = 10;
cin >> T;
for (test_case = 1; test_case <= T; test_case++) {
int ans = 0;
string str = "";
string buf = "";
cin >> str;
buf += str[0];
for (int i = 1; str.size(); i++) {
if (buf == str.substr(buf.size(), i)) {
ans = i;
break;
}
else {
buf += str[i];
}
}
cout << "#" << N << " " << ans << '\n';
}
return 0;
}'Programming Practice > SWEA' 카테고리의 다른 글
| [SWEA] 1215. 회문1 - (C++) (0) | 2022.06.04 |
|---|---|
| [SWEA] 1209. SUM - D3 (C++) (0) | 2022.05.30 |
| [SWEA] 1926. 간단한 369게임 - D2 (C++) (0) | 2022.05.26 |
| [SWEA] 1210. 7일차 - 미로1 - D4 (C++) (0) | 2022.05.26 |
| [SWEA] 1210. 2일차 - Ladder1 - D4 (C++) (0) | 2022.05.24 |