diff --git a/code_study/Baekjoon/c/10845.c b/code_study/Baekjoon/c/10845.c new file mode 100644 index 0000000..5b0952a --- /dev/null +++ b/code_study/Baekjoon/c/10845.c @@ -0,0 +1,65 @@ +#include +#include +#include + +int opcodeToNum(char* opcode); + +int main() { + int N; + scanf("%d\n",&N); + int queue[10000]; + int front = 0, rear = 0, size = 0; + + while(N--){ + char opcode[6]; + int operend; + scanf("%s",opcode); + + switch(opcodeToNum(opcode)) + { + case 0: + { + scanf("%d\n",&operend); + queue[rear++] = operend; + size++; + break; + } + case 1: + { + printf("%d\n", size ? queue[front++] : -1); + size = size ? size - 1 : 0; + break; + } + case 2: + { + printf("%d\n",size); + break; + } + case 3: + { + printf("%d\n", size ? 0 : 1); + break; + } + case 4: + { + printf("%d\n", size ? queue[front] : -1); + break; + } + case 5: + { + printf("%d\n", size ? queue[rear-1] : -1); + } + } + } + return 0; +} + +int opcodeToNum(char* opcode){ + if(!strcmp(opcode, "push")) return 0; + else if(!strcmp(opcode, "pop")) return 1; + else if(!strcmp(opcode, "size")) return 2; + else if(!strcmp(opcode, "empty")) return 3; + else if(!strcmp(opcode, "front")) return 4; + else if(!strcmp(opcode, "back")) return 5; + return -1; +} diff --git a/code_study/Baekjoon/c/11866.c b/code_study/Baekjoon/c/11866.c new file mode 100644 index 0000000..b854c37 --- /dev/null +++ b/code_study/Baekjoon/c/11866.c @@ -0,0 +1,35 @@ +#include +#include + +int nextIndex(int current_idx, int* arr, int n, int k); + +int main() { + int n, k; + scanf("%d %d",&n, &k); + int* list = (int*)malloc(sizeof(int)*(n+1)); + for(int i=0; i<=n; i++) { + list[i] = i; + } + + printf("<"); + int len = n, current_idx=1; + while(len!=0) { + current_idx = nextIndex(current_idx, list, n, len==n ? k-1 : k); + if(len==1) printf("%d>\n", list[current_idx]); + else printf("%d, ",list[current_idx]); + list[current_idx] = 0; + len--; + } + free(list); + return 0; +} + +int nextIndex(int current_idx, int* arr, int n, int k){ + while(k--){ + do{ + if(current_idx==n) current_idx = 1; + else current_idx++; + }while(arr[current_idx]==0); + } + return current_idx; +}