-
[백준] 1316 c++ 그룹 단어 체커STUDY/C++, C#, VB6, PYTHON 2022. 8. 25. 03:25
https://www.acmicpc.net/problem/1316
0. 예를들어 aabbbccb가 주어졌다고 가정한다.
1. aabbbccb 를 unique 함수를사용 - > abcb abbc 가 된다. ( 연속되는 중복되는값을 맨 뒤로 보낸다. )
2. 뒤에 중복된 값인 abbc를 erase를 통해 삭제. -> 그럼 abcb만 남게된다.
3. abcb를 sort한다. -> abbc (꼭! 먼저 중복되는값을 삭제해준후 정렬해주자)
4. for문을통해 0부터 length -1 만큼 비교해준다.
# j ==0 :: if a == b
# j == 1 :: if b==b -> isGroup = false
# j == 2 :: if b==c
5. aabbbccb는 그룹단어가 아니다.
#include <iostream> #include <algorithm> #include <vector> #include <array> #include <cmath> #include <functional> #include <string> using namespace std; void fastIO(); int main() { fastIO(); int N; int num = 0; string str; cin >> N; for (auto i = 0; i < N; i++) { bool isGroup = true; cin >> str; str.erase(unique(str.begin(), str.end()), str.end()); sort(str.begin(), str.end()); for (auto j = 0; j < str.length() - 1; j++) { if (str[j] == str[j + 1]) { isGroup = false; break; } } if (isGroup) num++; } cout << num; } void fastIO() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
'STUDY > C++, C#, VB6, PYTHON' 카테고리의 다른 글
[백준] 2798 c++ 블랙잭 (0) 2022.08.25 [백준] 2869 c++ 달팽이는 올라가고 싶다 (0) 2022.08.25 [백준] 25304 c++ 영수증 (0) 2022.08.24 [백준] 2108 c++ 통계학 (0) 2022.08.22 [백준] 10814 c++ 나이순 정렬 (0) 2022.08.21