About/Algorithm
[백준 18119] 단어 암기 (C)
김징어
2023. 1. 31. 22:19
https://www.acmicpc.net/problem/18119
18119번: 단어 암기
준석이는 영어 단어를 외우려고 한다. 사전에는 N가지 단어가 적혀 있다. 모든 단어는 소문자이다. 단어 안에 있는 모든 알파벳을 알 때, 그 단어를 완전히 안다고 한다. 다음과 같은 쿼리들이 주
www.acmicpc.net
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
|
#include <stdio.h>
#define MAX_N 10001
#define MAX_LEN 1001
int N, M;
int arr[MAX_N] = { 0, };
int remember = 0;
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < 26; i++)
remember |= (1 << i);
char temp[MAX_LEN] = { 0, };
for (int i = 0; i < N; i++) {
scanf("%s", temp);
for (int j = 0; j < MAX_LEN; j++) {
if (temp[j] == 0)
break;
arr[i] |= (1 << (temp[j] - 'a'));
temp[j] = 0;
}
}
int o;
char x;
for(int i = 0; i < M; i++){
int result = 0;
scanf("%d %c", &o, &x);
if (o == 1)
remember &= ~(1 << (x - 'a'));
else
remember |= (1 << (x - 'a'));
for (int j = 0; j < N; j++)
if ((arr[j] & remember) == arr[j])
result++;
printf("%d\n", result);
}
}
|
cs |