본문 바로가기

Programming/Algorithm

[C++] 백준 1316 번 : 그룹 단어 체커

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



#include <iostream>

#include <string>

using namespace std;


int main() {

int N;

int cnt = 0;


cin >> N;

for (int j = 0; j < N; j++) {

string s;

cin >> s;

int seq = true;

int alpha[26] = { 0 };

for (int i = 1; i < s.length(); i++) {

alpha[s[i - 1] - 97]++;

if (s[i - 1] != s[i])

if (alpha[s[i] - 97] != 0) {

seq = false;

break;

}

}

if (seq) cnt++;

}

cout << cnt << '\n';

}