본문 바로가기

Algorithm/BAEKJOON

[BOJ] 1316번 그룹 단어 체커 (C++)

728x90
반응형

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

 

1316번: 그룹 단어 체커

그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때

www.acmicpc.net

 

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, cnt = 0;
	cin >> n;
	string str;
	for(int i = 0; i < n; i++){
		cin >> str;
		set<char> s;
		char last = ' ';
		bool isTrue = true;
		for(int j = 0; j < str.length(); j++){
			if(last == str[j]){
				continue;
			} else{
				if(s.find(str[j]) != s.end()){
					isTrue = false;
					break;
				} 
				s.insert(str[j]);
				last = str[j];
			}
		}
		if(isTrue) cnt++;
	}
	cout << cnt << endl;
	return 0;
}
728x90
반응형