20250703 baekjoon
This commit is contained in:
parent
484b367ec5
commit
32461d9284
34
code_study/Baekjoon/c/11723.c
Normal file
34
code_study/Baekjoon/c/11723.c
Normal file
@ -0,0 +1,34 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
int set = 0;
|
||||
int N;
|
||||
scanf("%d",&N);
|
||||
getchar();
|
||||
while(N--) {
|
||||
char str[20];
|
||||
if (fgets(str, sizeof(str), stdin) == NULL) break;
|
||||
if (str[0] == '\n') { N++; continue; }
|
||||
str[strcspn(str, "\n")] = 0;
|
||||
char *opcode = strtok(str, " ");
|
||||
char *operend = strtok(NULL, " ");
|
||||
|
||||
if(!strcmp(opcode, "add")) {
|
||||
set |= 1 << (atoi(operend)-1);
|
||||
} else if(!strcmp(opcode, "remove")) {
|
||||
set &= ~(1 << (atoi(operend)-1));
|
||||
} else if(!strcmp(opcode, "check")) {
|
||||
printf("%d\n",set & (1 << (atoi(operend)-1)) ? 1 : 0);
|
||||
} else if(!strcmp(opcode, "toggle")) {
|
||||
set ^= 1 << (atoi(operend)-1);
|
||||
} else if(!strcmp(opcode, "all")) {
|
||||
set = (1<<20) - 1;
|
||||
} else if(!strcmp(opcode, "empty")) {
|
||||
set = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user