Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

새싹교실/2020/이찌반/전성수: Difference between revisions

From ZeroWiki
imported>stome6746
({CREATE})
 
imported>stome6746
No edit summary
Line 1: Line 1:
Describe 새싹교실/2020/이찌반/전성수 here
'''약수의 합'''
'''약수의 합'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
 
int solution(int n) {
int solution(int n) {
    int answer = 0;
    int answer = 0;
    for (int i = n; i &gt; 0; i--) {
    for (int i = n; i > 0; i--) {
        if (n % i == 0) {
        if (n % i == 0) {
            answer += i;
            answer += i;
        }
        }
        else continue;
        else continue;
    }
    }
    return answer;
    return answer;
}
}
 
'''하샤드수'''
'''하샤드수'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
 
bool solution(int x) {
bool solution(int x) {
    bool answer = true;
    bool answer = true;
    int sum = 0;
    int sum = 0;
    while (1) {
    while (1) {
        sum += x % 10;
        sum += x % 10;
        if (x / 10 &lt; 10) {
        if (x / 10 < 10) {
            sum += x / 10;
            sum += x / 10;
            break;
            break;
        }
        }
        else {
        else {
            x /= 10;
            x /= 10;
        }
        }
    }
    }
    if (x % sum == 0) answer = true;
    if (x % sum == 0) answer = true;
    else  answer = false;
    else  answer = false;
 
    return answer;
    return answer;
}
}
 
'''수박수박수'''
'''수박수박수'''
//하샤드 수
#include &lt;stdbool.h&gt;
#include <stdio.h>
#include &lt;stdlib.h&gt;
#include <stdbool.h>
#include <stdlib.h>
bool solution(int x) {
 
    bool answer = true;
bool solution(int x) {
    int sum = 0;
    bool answer = true;
    while (1) {
    int sum = 0;
        sum += x % 10;
    while (1) {
        if (x / 10 &lt; 10) {
        sum += x % 10;
            sum += x / 10;
        if (x / 10 < 10) {
            break;
            sum += x / 10;
        }
            break;
        else {
        }
            x /= 10;
        else {
        }
            x /= 10;
    }
        }
    if (x % sum == 0) answer = true;
    }
    else  answer = false;
    if (x % sum == 0) answer = true;
    else  answer = false;
    return answer;
 
}
    return answer;
}
 
'''두개 뽑아서 더하기'''
'''두개 뽑아서 더하기'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
#define SWAP(a, b) {int t = a; a = b; b = t;}
#define SWAP(a, b) {int t = a; a = b; b = t;}
 
int* solution(int numbers[], size_t numbers_len) {
int* solution(int numbers[], size_t numbers_len) {
    int length = 0;
    int length = 0;
    int* answer = (int*)malloc(sizeof(int) * 100);
    int* answer = (int*)malloc(sizeof(int) * 100);
    for (int i = 0; i &lt; numbers_len - 1; i++) {
    for (int i = 0; i < numbers_len - 1; i++) {
        for (int j = i + 1; j &lt; numbers_len; j++) {
        for (int j = i + 1; j < numbers_len; j++) {
            int add = numbers[i] + numbers[j];
            int add = numbers&#91;i&#93; + numbers&#91;j&#93;;
            int check = 1;
            int check = 1;
            for (int k = 0; k &lt; length; k++) {
            for (int k = 0; k < length; k++) {
                if (answer[k] == add) check = 0;
                if (answer&#91;k&#93; == add) check = 0;
            }
            }
            if (check == 1) {
            if (check == 1) {
                answer[length] = add;
                answer&#91;length&#93; = add;
                length++;
                length++;
            }
            }
        }
        }
    }
    }
    for (int i = 0; i &lt; length; i++) {
    for (int i = 0; i < length; i++) {
        for (int j = 0; j &lt; length - 1; j++) {
        for (int j = 0; j < length - 1; j++) {
            if (answer[j] &gt; answer[j + 1]) SWAP(answer[j], answer[j + 1]);
            if (answer&#91;j&#93; > answer[[j + 1]]) SWAP(answer&#91;j&#93;, answer[[j + 1]]);
        }
        }
    }
    }
    return answer;
    return answer;
}
}
 
'''- 별찍기'''
'''- 별찍기'''
//별찍기
#include <stdio.h>
int main(void) {
 
    int a;
int main(void) {
    int b;
    int a;
    scanf_s("%d %d", &amp;a, &amp;b);
    int b;
    printf("%d\n", a + b);
    scanf_s("%d %d", &a, &b);
    for (int i = 0; i &lt; b; i++) {
    printf("%d\n", a + b);
    for (int i = 0; i < b; i++) {
        for (int j = 0; j &lt; a; j++) {
 
            printf("*");
        for (int j = 0; j < a; j++) {
        }
            printf("*");
        }
        printf("\n");
 
    }
        printf("\n");
    return 0;
    }
}
    return 0;
}
 
'''문자열 정렬'''
'''문자열 정렬'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
#include &lt;string.h&gt;
#include <string.h>
#define SWAP(a,b) {int t = a;a = b;b = t;}
#define SWAP(a,b) {int t = a;a = b;b = t;}
char* solution(const char* s) {
char* solution(const char* s) {
    int cnt = strlen(s);
    int cnt = strlen(s);
    char* answer = (char*)malloc(sizeof(char) * cnt);
    char* answer = (char*)malloc(sizeof(char) * cnt);
    for (int i = 0; i &lt;= cnt; i++) {
    for (int i = 0; i <= cnt; i++) {
        answer[i] = s[i];
        answer&#91;i&#93; = s&#91;i&#93;;
    }
    }
    for (int i = 0; i &lt; cnt; i++) {
    for (int i = 0; i < cnt; i++) {
        for (int j = 0; j &lt; cnt - 1; j++) {
        for (int j = 0; j < cnt - 1; j++) {
            if (answer[j] &lt;= answer[j + 1]) {
            if (answer&#91;j&#93; <= answer[[j + 1]]) {
                SWAP(answer[j], answer[j + 1]);
                SWAP(answer&#91;j&#93;, answer[[j + 1]]);
            }
            }
        }
        }
    }
    }
    return answer;
    return answer;
}
}
 
'''문자열을 정수로 바꾸기'''
'''문자열을 정수로 바꾸기'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
 
int solution(const char* s) {
int solution(const char* s) {
    int answer = 0;
    int answer = 0;
    answer = atoi(s);
    answer = atoi(s);
    return answer;
    return answer;
}
}
 
'''문자열 다루기'''
'''문자열 다루기'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
#include &lt;string.h&gt;
#include <string.h>
#include &lt;ctype.h&gt;
#include <ctype.h>
 
bool solution(const char* s) {
bool solution(const char* s) {
    bool answer = true;
    bool answer = true;
    int count = strlen(s);
    int count = strlen(s);
 
    for (int i = 0; i &lt; count; i++) {
    for (int i = 0; i < count; i++) {
        if (isalpha(s[i])) {
        if (isalpha(s&#91;i&#93;)) {
            answer = false;
            answer = false;
        }
        }
    }
    }
    if ((count == 4 || count == 6) != 1) {
    if ((count == 4 || count == 6) != 1) {
        answer = false;
        answer = false;
    }
    }
 
    return answer;
    return answer;
}
}
 
'''두 정수 사이의 합'''
'''두 정수 사이의 합'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
 
long long solution(int a, int b) {
long long solution(int a, int b) {
    long long answer = 0;
    long long answer = 0;
    long long sum = 0;
    long long sum = 0;
    if (a &gt; b) {
    if (a > b) {
        for (int i = b; i &lt;= a; i++) {
        for (int i = b; i <= a; i++) {
            sum += i;
            sum += i;
        }
        }
        answer = sum;
        answer = sum;
    }
    }
    else if (a &lt; b) {
    else if (a < b) {
        for (int i = a; i &lt;= b; i++) {
        for (int i = a; i <= b; i++) {
            sum += i;
            sum += i;
        }
        }
        answer = sum;
        answer = sum;
    }
    }
    else {
    else {
        answer = a;
        answer = a;
    }
    }
    return answer;
    return answer;
}
}
 
'''가운데 글자 가져오기'''
'''가운데 글자 가져오기'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
#include &lt;string.h&gt;
#include <string.h>
 
char* solution(const char* s) {
char* solution(const char* s) {
    char* answer;
    char* answer;
    int cnt = strlen(s);
    int cnt = strlen(s);
    if (cnt % 2) {
    if (cnt % 2) {
        answer = (char*)malloc(sizeof(char));
        answer = (char*)malloc(sizeof(char));
        answer[0] = s[cnt / 2];
        answer&#91;0&#93; = s[[cnt / 2]];
        answer[1] = '\0';
        answer&#91;1&#93; = '\0';
    }
    }
    else {
    else {
        answer = (char*)malloc(sizeof(char) * 2);
        answer = (char*)malloc(sizeof(char) * 2);
        answer[0] = s[(cnt / 2) - 1];
        answer&#91;0&#93; = s[[(cnt / 2) - 1]];
        answer[1] = s[cnt / 2];
        answer&#91;1&#93; = s[[cnt / 2]];
        answer[2] = '\0';
        answer&#91;2&#93; = '\0';
    }
    }
    return answer;
    return answer;
}
}
 
'''2016년'''
'''2016년'''
#include <stdio.h>
#include &lt;stdbool.h&gt;
#include <stdbool.h>
#include &lt;stdlib.h&gt;
#include <stdlib.h>
char* solution(int a, int b) {
//5. 24(1,2,3,4,
    char* answer = (char*)malloc(sizeof(char) * 10);
char* solution(int a, int b) {
    int day = b;
    // 리턴할 값은 메모리를 동적 할당해주세요.
    int month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    char* answer = (char*)malloc(sizeof(char) * 10);
    for (int i = 0; i &lt; a; i++) {
    int day = b;
        day += month[i - 1];
    int month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    }
    for (int i = 0; i < a; i++) {
    switch (day % 7) {
        day += month[[i - 1]];
    case 0: answer = "THU"; break;
    }
    case 1: answer = "FRI"; break;
    switch (day % 7) {
    case 2: answer = "SAT"; break;
    case 0: answer = "THU"; break;
    case 3: answer = "SUN"; break;
    case 1: answer = "FRI"; break;
    case 4: answer = "MON"; break;
    case 2: answer = "SAT"; break;
    case 5: answer = "TUE"; break;
    case 3: answer = "SUN"; break;
    case 6: answer = "WED"; break;
    case 4: answer = "MON"; break;
    }
    case 5: answer = "TUE"; break;
    return answer;
    case 6: answer = "WED"; break;
}
    }
    return answer;
}



Revision as of 07:05, 3 October 2020

약수의 합

#include <stdbool.h>
#include <stdlib.h>

int solution(int n) {
    int answer = 0;
    for (int i = n; i > 0; i--) {
        if (n % i == 0) {
            answer += i;
        }
        else continue;
    }
    return answer;
}

하샤드수

#include <stdbool.h>
#include <stdlib.h>

bool solution(int x) {
    bool answer = true;
    int sum = 0;
    while (1) {
        sum += x % 10;
        if (x / 10 < 10) {
            sum += x / 10;
            break;
        }
        else {
            x /= 10;
        }
    }
    if (x % sum == 0) answer = true;
    else  answer = false;

    return answer;
}

수박수박수

#include <stdbool.h>
#include <stdlib.h>

bool solution(int x) {
    bool answer = true;
    int sum = 0;
    while (1) {
        sum += x % 10;
        if (x / 10 < 10) {
            sum += x / 10;
            break;
        }
        else {
            x /= 10;
        }
    }
    if (x % sum == 0) answer = true;
    else  answer = false;

    return answer;
}

두개 뽑아서 더하기

#include <stdbool.h>
#include <stdlib.h>
#define SWAP(a, b) {int t = a; a = b; b = t;}

int* solution(int numbers[], size_t numbers_len) {
    int length = 0;
    int* answer = (int*)malloc(sizeof(int) * 100);
    for (int i = 0; i < numbers_len - 1; i++) {
        for (int j = i + 1; j < numbers_len; j++) {
            int add = numbers[i] + numbers[j];
            int check = 1;
            for (int k = 0; k < length; k++) {
                if (answer[k] == add) check = 0;
            }
            if (check == 1) {
                answer[length] = add;
                length++;
            }
        }
    }
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length - 1; j++) {
            if (answer[j] > answer[j + 1]) SWAP(answer[j], answer[j + 1]);
        }
    }
    return answer;
}

- 별찍기

int main(void) {
    int a;
    int b;
    scanf_s("%d %d", &a, &b);
    printf("%d\n", a + b);
    for (int i = 0; i < b; i++) {

        for (int j = 0; j < a; j++) {
            printf("*");
        }

        printf("\n");
    }
    return 0;
}

문자열 정렬

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#define SWAP(a,b) {int t = a;a = b;b = t;}
char* solution(const char* s) {
    int cnt = strlen(s);
    char* answer = (char*)malloc(sizeof(char) * cnt);
    for (int i = 0; i <= cnt; i++) {
        answer[i] = s[i];
    }
    for (int i = 0; i < cnt; i++) {
        for (int j = 0; j < cnt - 1; j++) {
            if (answer[j] <= answer[j + 1]) {
                SWAP(answer[j], answer[j + 1]);
            }
        }
    }
    return answer;
}

문자열을 정수로 바꾸기

#include <stdbool.h>
#include <stdlib.h>

int solution(const char* s) {
    int answer = 0;
    answer = atoi(s);
    return answer;
}

문자열 다루기

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

bool solution(const char* s) {
    bool answer = true;
    int count = strlen(s);

    for (int i = 0; i < count; i++) {
        if (isalpha(s[i])) {
            answer = false;
        }
    }
    if ((count == 4 || count == 6) != 1) {
        answer = false;
    }

    return answer;
}

두 정수 사이의 합

#include <stdbool.h>
#include <stdlib.h>

long long solution(int a, int b) {
    long long answer = 0;
    long long sum = 0;
    if (a > b) {
        for (int i = b; i <= a; i++) {
            sum += i;
        }
        answer = sum;
    }
    else if (a < b) {
        for (int i = a; i <= b; i++) {
            sum += i;
        }
        answer = sum;
    }
    else {
        answer = a;
    }
    return answer;
}

가운데 글자 가져오기

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

char* solution(const char* s) {
    char* answer;
    int cnt = strlen(s);
    if (cnt % 2) {
        answer = (char*)malloc(sizeof(char));
        answer[0] = s[cnt / 2];
        answer[1] = '\0';
    }
    else {
        answer = (char*)malloc(sizeof(char) * 2);
        answer[0] = s[(cnt / 2) - 1];
        answer[1] = s[cnt / 2];
        answer[2] = '\0';
    }
    return answer;
}

2016년

#include <stdbool.h>
#include <stdlib.h>
char* solution(int a, int b) {
    char* answer = (char*)malloc(sizeof(char) * 10);
    int day = b;
    int month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    for (int i = 0; i < a; i++) {
        day += month[i - 1];
    }
    switch (day % 7) {
    case 0: answer = "THU"; break;
    case 1: answer = "FRI"; break;
    case 2: answer = "SAT"; break;
    case 3: answer = "SUN"; break;
    case 4: answer = "MON"; break;
    case 5: answer = "TUE"; break;
    case 6: answer = "WED"; break;
    }
    return answer;
}