개인공부용123 프로그래밍 블로그

[백준] boj1316 본문

알고리즘문제

[백준] boj1316

개인공부용123 2020. 7. 6. 23:00
#include <iostream>
using namespace std;

void init(char* str, bool* chk) {
	for (int i = 0; i <= 100; ++i) 
		str[i] = 0;
	
	for (int i = 0; i < 27; ++i)
		chk[i] = false;
}

int main() {
	//freopen("test.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int T, cnt;
	char str[101], c, prev_c;
	bool chk[27];

	cnt = 0;

	cin >> T;

	while (T--) {
		init(str,chk);
		prev_c = 0;

		cin >> str;

		for (int i = 0; str[i] != 0; ++i) {
			c = str[i];
			
			if (c != prev_c && chk[c - 'a']) {
				--cnt;
				break;
			}
			
			chk[c - 'a'] = true;
			prev_c = c;
		}

		++cnt;
		
	}

	cout << cnt << endl;

	return 0;
}

 

아이디어 : 문자를 하나씩 확인하여 이전 문자와 다르고 이미 체크 된 문자이면 그룹 단어가 아님

구현 : 배열을 이용한 단순 구현

'알고리즘문제' 카테고리의 다른 글

[백준] boj10872  (0) 2020.08.10
[백준] boj 2751  (0) 2020.08.09
[백준] 6591  (0) 2017.05.19
[백준] 11051 이항계수문제  (0) 2017.05.19
[백준] 5430  (0) 2017.05.04