Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
4.4 kB
1
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
int ex1(int year) {
    if (year%100==0 && year/100%4!=0) return 0;
    if (year%4==0) return 1;
    return 0;
}

void ex2dop(int temp) {
    switch (temp) {
        case 1:
            printf("крысы\n\n");
            break;
        case 2:
            printf("коровы\n\n");
            break;
        case 3:
            printf("тигра\n\n");
            break;
        case 4:
            printf("зайца\n\n");
            break;
        case 5:
            printf("дракона\n\n");
            break;
        case 6:
            printf("змеи\n\n");
            break;
        case 7:
            printf("лошади\n\n");
            break;
        case 8:
            printf("овцы\n\n");
            break;
        case 9:
            printf("обезьяны\n\n");
            break;
        case 10:
            printf("курицы\n\n");
            break;
        case 11:
            printf("собаки\n\n");
            break;
        case 12:
            printf("свиньи\n\n");
            break;
    }
}

void swcase(int year) {
    int ost = year%60/12+1;
    int temp = year%60%12-3;
    switch (ost) {
        case 1:
            printf("год зеленой ");
            ex2dop(temp);
            break;
        case 2:
            printf("год красной ");
            ex2dop(temp);
            break;
        case 3:
            printf("год желтой ");
            ex2dop(temp);
            break;
        case 4:
            printf("год белой ");
            ex2dop(temp);
            break;
        case 5:
            printf("год черной ");
            ex2dop(temp);
            break;
    }
}

int countSeven(int x) {
    int count = 0;
    while (x != 0) {
        if (x%10==7) count++;
        x/=10;
    }
    return count;
}

int ex5(int num){
    if (num == 0) return 0;
    if (num%9==0) return 9;
    return num%9;
}

void game() {
    printf("START GAME\n");
    int target = rand()%1000+1;
    int try = 10;
    while (try != 0) {
        int t;
        printf("Enter number: \n");
        scanf("%d", &t);
        if (t == target) {
            printf("WIN\n\n");
            break;
        }
        else if (t > target) {
            printf("TOO HIGH\n");
        }
        else{
            printf("TOO LOW\n");
        }
        try--;
    }
    if (try == 0) printf("LOOOSE\n\n");
}

double ex7(double roud) {
    double s1 = 0, s2 = 0, n = 0;
    do {
        ++n;
        s1 = (s2+4/(2*n-1));
        n++;
        s2 = (s1-(4/(2*n-1)));
    } while (s1 - s2 > roud);
    return (s1+s2)/2;
}

int sumNRow(int numRow) {
    int first = numRow*(numRow-1)+1;
    int last = numRow*(numRow+1)-1;
    return (first+last)/2*numRow;
    // return row*row*row;
}

int GIGACHAD(int arr[], int length, int amount) {
    int c[amount + 1];
    for (int i = 0; i <= amount; i++) {
        c[i] = amount+1;
    }
    
    c[0] = 0;
    for (int i = 1; i <= amount; i++) {
        for (int j = 0; j < length; j++) {
            if (arr[j] <= i) {
                if (c[i] > c[i-arr[j]]+1) {
                    c[i] = c[i-arr[j]]+1;
                }
            }
        }
    }
    return c[amount] > amount ? -1 : c[amount];
}

int main()
{

    //ex 1
    int year;
    printf("Enter year: \n");
    scanf("%d", &year);
    ex1(year) ? printf("YES\n\n") : printf("NO\n\n");
    
    //ex2
    printf("enter year\n");
    scanf("%d", &year);
    swcase(year);
    
    //ex3
    printf("Ex3 \n");
    int resEX3 = 0;
    for (int i = 1; i < 1000; i++) {
        resEX3 += countSeven(i);
    }
    printf("%d\n\n", resEX3);
    
    //ex4
    printf("Ex4 \n");
    int resEX4 = 0;
    for (int i = 1; i < 1000; i++) {
        resEX4 += (countSeven(i) > 0);
    }
    printf("%d\n\n", resEX4);
    
    //ex5
    int num;
    printf("Enter num: \n");
    scanf("%d", &num);
    printf("%d\n\n", ex5(num));
    
    //ex6
    game();
    
    //ex7
    double roud;
    printf("Enter round: \n");
    scanf("%lf", &roud);
    printf("%lf\n\n", ex7(roud));
    
    //ex8
    int row;
    printf("Enter n-row: \n");
    scanf("%d", &row);
    printf("%d\n\n", sumNRow(row));
    
    
    //ex9
    int length = 4;
    int arr[4] = {19, 23, 37, 41};
    int amount;
    printf("Enter amount: \n");
    scanf("%d", &amount);
    printf("GIGACHAD = %d", GIGACHAD(arr, length, amount));
    return 0;
}