알고리즘 문제/BOJ
1316번 그룹 단어 체커
parkit
2018. 10. 27. 19:21
728x90
반응형
https://www.acmicpc.net/problem/1316
단어를 검사할 때, 그 해당하는 '문자'에 대한 사용횟수와 '연속'으로 같은 길이를 잰다.
사용횟수와 길이가 다르다면, 이미 그 전에 사용한 적이 있는 경우이므로,
이 경우를 제외하고 셈하면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; int N = 0; int main(void) { scanf("%d", &N); char str[110]; int used[130] = { 0, }, result = 0; for (int i = 0; i < N; i++) { memset(used, 0, sizeof(used)); scanf("%s", str); int len = strlen(str); int is = -1; for (int j = 0; j < len; j++) { int Length = 1; ++used[str[j]]; while (j + 1 < len && str[j] == str[j + 1]) { ++used[str[j]]; ++j; ++Length; } if (used[str[j]] != Length) { is = 1; break; } } if (is == -1) { ++result; } } printf("%d\n", result); return 0; } | cs |
728x90
반응형