Baekjoon[백준] 1316 그룹단어체커 문제 C++ 풀이

less than 1 minute read

문제 링크

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


안녕하세요.

SW 알고리즘 문제로 유명한 사이트 Baekjoon Online Judge의 소스코드를 공유해드립니다.

도움이 되었으면 좋겠습니다.

감사합니다.


해답

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

int cnt = 0; 
void check(string a);

int main()
{
	int n;
	cin >> n;
	string str;

	for (int i = 0; i < n; i++)
	{
		cin >> str;
		check(str);

	}

	cout << cnt;


	return 0;
}

void check(string a)
{
	int siz = a.size();
	
	for (int i = 0; i < siz - 2; i++)
	{
		if (a[i] != a[i + 1]) 
		{
			for (int j = i + 2; j < siz; j++)
				if (a[j] == a[i])
					return; 
		}

	}

	cnt++; 

}

Leave a comment