From bda4f18113fcc9882a026b999110ecfb18296cd4 Mon Sep 17 00:00:00 2001 From: wil3992 Date: Thu, 4 May 2023 10:46:30 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[3=EC=A3=BC=EC=B0=A8]=EC=9D=B4=EC=83=81?= =?UTF-8?q?=ED=98=84=20=EA=B3=BC=EC=A0=9C=20=EC=A0=9C=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week 3/Week3_2438.c" | 18 ++++++++++++++ .../Week 3/Week3_2439.c" | 24 +++++++++++++++++++ .../Week 3/Week3_2440.c" | 16 +++++++++++++ .../Week 3/Week3_2441.c" | 20 ++++++++++++++++ .../Week 3/Week3_2442.c" | 20 ++++++++++++++++ .../Week 3/delete_me_plz" | 0 6 files changed, 98 insertions(+) create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 3/Week3_2438.c" create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 3/Week3_2439.c" create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 3/Week3_2440.c" create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 3/Week3_2441.c" create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 3/Week3_2442.c" delete mode 100644 "\354\235\264\354\203\201\355\230\204/Week 3/delete_me_plz" diff --git "a/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2438.c" "b/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2438.c" new file mode 100644 index 0000000..b5911d1 --- /dev/null +++ "b/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2438.c" @@ -0,0 +1,18 @@ +#include + +int main() +{ + int N; + scanf("%d",&N); + + for(int i=0;i + +int main() +{ + int N; + + scanf("%d",&N); + + for (int a = 1; a <= N; a++) + { + for (int i = 0; i < N - a; i++) + { + printf(" "); + } + + for (int j = 0; j < a; j++) + { + printf("*"); + } + + printf("\n"); + } + return 0; +} diff --git "a/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2440.c" "b/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2440.c" new file mode 100644 index 0000000..0321ad9 --- /dev/null +++ "b/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2440.c" @@ -0,0 +1,16 @@ +#include + +int main() +{ + int N; + scanf("%d", &N); + + for (int i = 0; i < N; i++) + { + for (int j=1; j<= N-i; j++) + { + printf("*"); + } + printf("\n"); + } +} \ No newline at end of file diff --git "a/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2441.c" "b/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2441.c" new file mode 100644 index 0000000..58142f3 --- /dev/null +++ "b/\354\235\264\354\203\201\355\230\204/Week 3/Week3_2441.c" @@ -0,0 +1,20 @@ +#include + +int main() +{ + int N,j,k; + scanf("%d", &N); + + for (int i = 0; i < N; i++) + { + for (j=0; j + +int main() +{ + int N, j, k; + scanf("%d", &N); + + for (int i = 0; i < N; i++) + { + for (j = 0; j < N - i-1; j++) + { + printf(" "); + } + for (k = 0; k < i * 2 + 1; k++) + { + printf("*"); + } + printf("%c", '\n'); + } +} \ No newline at end of file diff --git "a/\354\235\264\354\203\201\355\230\204/Week 3/delete_me_plz" "b/\354\235\264\354\203\201\355\230\204/Week 3/delete_me_plz" deleted file mode 100644 index e69de29..0000000 From a0b022b17770cb40f6746fd262666088f8064756 Mon Sep 17 00:00:00 2001 From: wil3992 Date: Wed, 10 May 2023 01:37:28 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[4=EC=A3=BC=EC=B0=A8]=EC=9D=B4=EC=83=81?= =?UTF-8?q?=ED=98=84=20=EA=B3=BC=EC=A0=9C=20=EC=A0=9C=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week 4/Week4_inq_atoi.c" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 4/Week4_inq_atoi.c" diff --git "a/\354\235\264\354\203\201\355\230\204/Week 4/Week4_inq_atoi.c" "b/\354\235\264\354\203\201\355\230\204/Week 4/Week4_inq_atoi.c" new file mode 100644 index 0000000..55c5620 --- /dev/null +++ "b/\354\235\264\354\203\201\355\230\204/Week 4/Week4_inq_atoi.c" @@ -0,0 +1,35 @@ +#define INT_MAX 2147483647 +#define INT_MIN (-INT_MAX - 1) + +int inq_atoi(char* str) +{ + int result = 0; + int plus_minus = 1; + + while (*str == ' ') + str++; + + if (*str == '-') + { + plus_minus = -1; + str++; + } + else if (*str == '+') + str++; + + + while (*str >= '0' && *str <= '9') + { + if (plus_minus == 1 && (result * 10 > INT_MAX || (result == INT_MAX && *str - '0' > INT_MAX % 10))) + { + return INT_MAX; + } + else if ( plus_minus == -1 && (result * 10 < -INT_MAX || (result == INT_MAX && *str - '0' > INT_MAX % 10))) + { + return INT_MIN; + } + result = (result * 10) + (*str - '0'); + str++; + } + return plus_minus * result; +} \ No newline at end of file From 98c00f28da307cbe6d99fb84f90f0bdcb2f8bf9d Mon Sep 17 00:00:00 2001 From: wil3992 Date: Thu, 8 Jun 2023 16:53:38 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[5=EC=A3=BC=EC=B0=A8]=20=EC=9D=B4=EC=83=81?= =?UTF-8?q?=ED=98=84=20=EA=B3=BC=EC=A0=9C=20=EC=A0=9C=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\352\263\274\354\240\234/inq_atoi.md" | 1 - .../Week 5/Week5_1475.c" | 27 ++++++++++ .../Week 5/Week5_2577.c" | 21 ++++++++ .../Week 5/Week5_3273.c" | 52 +++++++++++++++++++ 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 5/Week5_1475.c" create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 5/Week5_2577.c" create mode 100644 "\354\235\264\354\203\201\355\230\204/Week 5/Week5_3273.c" diff --git "a/\352\263\274\354\240\234/inq_atoi.md" "b/\352\263\274\354\240\234/inq_atoi.md" index 68fcaaf..09a666c 100644 --- "a/\352\263\274\354\240\234/inq_atoi.md" +++ "b/\352\263\274\354\240\234/inq_atoi.md" @@ -35,7 +35,6 @@ - 테스트 목적으로 사용하는 것은 허용하나, 제출 파일 및 함수 구현 과정에서는 절대 포함할 수 없습니다. - 함정이 있어요! - **정수 최댓값, 최솟값 리턴을 어떻게 할지 고심해보세요.** - - INT_MAX를 초과하는 값이나, INT_MIN 미만의 값이 input될 경우, overflow와 underflow를 자연스럽게 처리해야 합니다. - (사용하지는 않겠지만) malloc을 사용할 경우, Memory Leak은 허용하지 않습니다. - 전역변수 사용이 금지됩니다. 함수 분리, 메서드 분리는 지역 변수를 이용하여 parameter로 처리하세요. - 전체 함수 및 메서드는 `int inq_atoi(char *str)`함수를 포함해 5개 이하로 작성하세요. diff --git "a/\354\235\264\354\203\201\355\230\204/Week 5/Week5_1475.c" "b/\354\235\264\354\203\201\355\230\204/Week 5/Week5_1475.c" new file mode 100644 index 0000000..976d875 --- /dev/null +++ "b/\354\235\264\354\203\201\355\230\204/Week 5/Week5_1475.c" @@ -0,0 +1,27 @@ +#include + +int main() +{ + int a, sum, max; + int d[10] = {0}; + scanf("%d", &a); + while (a > 0) + { + sum = a % 10; + d[sum]++; + a /= 10; + } + + max = (d[6] + d[9] + 1) / 2; + + for (int i = 0; i < 10; i++) + { + if (i == 6 || i == 9) + continue; + else if (d[i] > max) + { + max = d[i]; + } + } + printf("%d",max); +} \ No newline at end of file diff --git "a/\354\235\264\354\203\201\355\230\204/Week 5/Week5_2577.c" "b/\354\235\264\354\203\201\355\230\204/Week 5/Week5_2577.c" new file mode 100644 index 0000000..54f537e --- /dev/null +++ "b/\354\235\264\354\203\201\355\230\204/Week 5/Week5_2577.c" @@ -0,0 +1,21 @@ +#include + +int main() +{ + + int A, B, C, sum, res; + int a[10] = { 0 }; + scanf("%d %d %d", &A, &B, &C); + sum = A * B * C; + + while (sum >0) { + res = sum % 10; + a[res]++; + sum /= 10; + } + for (int i = 0; i < 10; i++) + { + printf("%d\n", a[i]); + } + +} \ No newline at end of file diff --git "a/\354\235\264\354\203\201\355\230\204/Week 5/Week5_3273.c" "b/\354\235\264\354\203\201\355\230\204/Week 5/Week5_3273.c" new file mode 100644 index 0000000..214c40e --- /dev/null +++ "b/\354\235\264\354\203\201\355\230\204/Week 5/Week5_3273.c" @@ -0,0 +1,52 @@ +#include +#include + +int compare(const void* a, const void* b) { + return (*(int*)a - *(int*)b); +} + +int countPairs(int* sequence, int n, int x) { + int count = 0; + int i = 0; + int j = n - 1; + + while (i < j) { + if (sequence[i] + sequence[j] == x) { + count++; + i++; + j--; + } + else if (sequence[i] + sequence[j] < x) { + i++; + } + else { + j--; + } + } + + return count; +} + +int main() { + int n; + scanf("%d", &n); + + int* sequence = (int*)malloc(n * sizeof(int)); + if (sequence == NULL) { + return 1; + } + + for (int i = 0; i < n; i++) { + scanf("%d", &sequence[i]); + } + + int x; + scanf("%d", &x); + qsort(sequence, n, sizeof(int), compare); + int result = countPairs(sequence, n, x); + printf("%d\n", result); + + free(sequence); + + return 0; +} \ No newline at end of file