728x90
반응형
- 풀이 링크:
GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이
알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.
github.com
#include <iostream>
#include <algorithm>
//#include <map> // 중복 x
#include <string> // getline
#include <cstring> // memset, strok, strstr
//#include <vector>
//#include <queue>
//#include <set> // 트리, 중복 x
//#include <unordered_set>
using namespace std;
/*
[백준 1316 c++ OO] 그룹 단어 체커
접근1:
시간복잡도: n*n
풀이:
//1.입력
//2.완탐: 문자열 탐색하며 전과 다른 문자가 나왔는데 이미 그 문자가 나온적 있으면 그룹단어 아님
//3.출력:
*/
int n;
string a;
int cnt[26 + 10];
int res = 0;
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0);
//1.입력
cin >> n;
//2.완탐: 문자열 탐색하며 전과 다른 문자가 나왔는데 이미 그 문자가 나온적 있으면 그룹단어 아님
while (n--) {
bool isGroup = 1;
memset(cnt, 0, sizeof(cnt));
cin >> a;
cnt[a[0] - 'a']++;
int size = a.size();
for (int i = 1; i < size; i++) {
if (cnt[a[i] - 'a'] == 0) cnt[a[i] - 'a']++;
else if (a[i] != a[i - 1] && cnt[a[i]-'a']!=0) {
isGroup = 0;
break;
}
}
if (isGroup) res++;
}
//3.출력:
cout << res << '\n';
return 0;
}
반응형
'Algorithm_BOJ(백준) > 문자열' 카테고리의 다른 글
[백준 4659 c++ V] 비밀번호 발음하기 (0) | 2023.01.23 |
---|---|
[백준 16171 c++ O] 나는 친구가 적다 (Small) (0) | 2023.01.22 |
[백준 10798 c++ O] 세로읽기 (0) | 2023.01.22 |
[백준 16916 c++ V] 부분 문자열 (0) | 2023.01.22 |
[백준 9046 c++ V] 복호화 (0) | 2023.01.22 |