Introduction to C language 130 questions - OJ

BC1 practice produces true knowledge

#include <stdio.h>
int main()
{
    printf("Practice makes perfect!\n");
    return 0;
}

BC2 I'm big V

#include <stdio.h>
int main()
{
    printf("v   v\n v v \n  v  \n");
    return 0;
}

BC3 has capacity

#include <stdio.h>
int main()
{
    printf("The size of short is %d bytes.\n", sizeof(short));
    printf("The size of int is %d bytes.\n", sizeof(int));
    printf("The size of long is %d bytes.\n", sizeof(long));
    printf("The size of long long is %d bytes.\n", sizeof(long long));
}

BC6 small aircraft

#include <stdio.h>
int main()
{
    printf("     **     \n");
    printf("     **     \n");
    printf("************\n");
    printf("************\n");
    printf("    *  *    \n");
    printf("    *  *    \n");
    return 0;
}

BC7 shortened binary

#include <stdio.h>
int main()
{
//     printf("0%o 0X%X", 1234, 1234);
    printf("%#o %#X", 1234, 1234);
    return 0;
}

BC8 hex to decimal

#include <stdio.h>
int main()
{
    int n = 0XABCDEF;
    printf("%15d", n);
    return 0;
}

Return value of BC9 printf

#include <stdio.h>
int main()
{
    int a = printf("Hello world!");
    printf("\n%d", a);
    return 0;
}

BC10 score input and output

#include <stdio.h>
int main()
{
    int score1 = 0;
    int score2 = 0;
    int score3 = 0;
    scanf("%d %d %d", &score1, &score2, &score3);
    printf("score1=%d,score2=%d,score3=%d", score1, score2, score3);
    return 0;
}

BC11 student basic information input and output

#include <stdio.h>
int main()
{
    long a;
    float C, M, E;
    scanf("%ld;%f,%f,%f", &a, &C, &M, &E);
    printf("The each subject score of No. %ld is %.2f, %.2f, %.2f.", a, C, M, E);
    return 0; 
}

BC12 character Christmas tree

#include<stdio.h>
int main()
{
    char a;
    scanf("%c", &a);//Enter an arbitrary character
    for(int i = 1; i <= 5; i++)
    {
        for(int j = 0; j < 5-i; j++)
        {
            printf(" ");
        }
        for(int j = 0; j < i; j++)
        {
            printf("%c ", a);
        }
        printf("\n");
    }
    return 0;
}

BC13 ASCII code

#include <stdio.h>
int main()
{
    int arr[] = {73, 32, 99, 97, 110, 32, 100, 111, 32, 105, 116 , 33};
    int size = sizeof(arr) / sizeof(arr[0]);
    for(int i = 0; i < size; i++)
    {
        printf("%c", arr[i]);
    }
    return 0;
}

BC14 date of birth input / output

#include <stdio.h>
int main()
{
    int year;
    int month;
    int day;
    scanf("%4d%2d%2d", &year, &month, &day);
    printf("year=%d\nmonth=%02d\ndate=%02d\n", year, month, day);
    return 0;
}

BC15 input and exchange output according to format

#include <stdio.h>
void JH(int *a, int *b);
int main()
{
    int a;
    int b;
    scanf("a=%d,b=%d", &a, &b);
    JH(&a, &b);
    printf("a=%d,b=%d", a, b);
    
}
void JH(int *a, int *b)
{
    int c = *a;
    *a = *b;
    *b = c;
}

BC16 character to ASCII

#include <stdio.h>
int main()
{
    char ch;
    while((ch = getchar()) != EOF)
    {
        getchar();
        printf("%d\n", ch);
    }
    return 0;
}

BC17 evaluate the value of an expression

#include <stdio.h>
int main()
{
    int a = 40;
    int c = 212;
    int num = (-8 + 22) * a - 10 + c / 2;
    printf("%d", num);
}

BC18 calculating division with remainder

#include <stdio.h>
int main()
{
    int a;
    int b;
    scanf("%d %d", &a, &b);
    printf("%d %d", a / b, a % b);
    return 0;
}

BC19 reversely outputs a four digit number

#include <stdio.h>
int main()
{
    int a;
    scanf("%d", &a);
    while(a > 0)
    {
        int b = a % 10;
        printf("%d", b);
        a = a / 10;
    }
}

BC20 kiki arithmetic

#include <stdio.h>
int main()
{
    int a;
    int b;
    scanf("%d %d", &a, &b);
    int c = a + b;
    if(c >= 100)
        c %= 100;
    printf("%d", c);
    return 0;
}

BC21 single digit of floating point number

#include <stdio.h>
int main()
{
    float a;
    scanf("%f", &a);
    int b = (int)a;
    printf("%d", b %= 10);
    return 0;
}

BC22 how many seconds can you live

#include <stdio.h>
int main()
{
    int age = 0;
    scanf("%d", &age);
    printf("%.0lf\n", age * 31560000.0);
    return 0;
}

BC23 time conversion

#include <stdio.h>
int main()
{
    int seconds = 0;
    int hour = 0, minute = 0, sec = 0;
    scanf("%d", &seconds);
    hour = seconds / 3600;
    minute = (seconds % 3600) / 60;
    sec = (seconds % 3600) % 60;
    printf("%d %d %d", hour, minute, sec);
}

BC24 total score and average score calculation

#include <stdio.h>
int main()
{
    double a[3] = {0};
    double sum = 0, ave = 0;
    scanf("%lf %lf %lf", &a[0], &a[1], &a[2]);
    printf("%.2f %.2f", a[0]+a[1]+a[2], (a[0]+a[1]+a[2])/3.0);
    return 0;
}

BC25 calculate body mass index

#include <stdio.h>
int main()
{
    int high = 0, weight = 0;
    scanf("%d %d", &weight, &high);
    printf("%.2f\n", weight / ((high / 100.0)*(high / 100.0)));
    return 0;
}

BC26 calculates the perimeter and area of a triangle

#include<stdio.h>
#include<math.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	float d, e, p;
	d = a + b + c;
	p = d / 2;
	e = sqrt(p * (p-a) *(p-b) * (p-c));
	printf("circumference=%.2f area=%.2f", d, e);
	return 0;
}

BC27 calculate the volume of the sphere

#include <stdio.h>
#include <math.h>
int main()
{
	//radius
	double r = 0.0;
	//volume
	double v = 0.0;
	double pi = 3.1415926;
	//input
	scanf("%lf", &r);
	//calculation
	v = 4 / 3.0 * pi * pow(r,3);
	//output
	printf("%.3lf\n", v);
	return 0;
}

BC28 case conversion

#include <stdio.h>
int main()
{
    char ch;
    while((ch = getchar()) != EOF)
    {
        getchar();  //Eliminate carriage return
        if(ch >= "a" && ch <= "z")
            printf("%c\n", (ch - 32));
        else
            printf("%c\n", (ch + 32));
    }
    return 0;
}

Bc29 n-th power calculation of 2

#include <stdio.h>
int main()
{
    int a;
    int sum = 1;
    scanf("%d", &a);
    for(int i = 0; i < a; i++)
    {
        sum = sum << 1;
    }
    printf("%d", sum);
    return 0;
}

BC30 KiKi and yogurt

#include <stdio.h>
int main()
{
    int n;
    int h;
    int m;
    scanf("%d %d %d", &n, &h, &m);
    int w = (n * h - m) / h;
    printf("%d", w);
    return 0;
}

BC31 release information

#include <stdio.h>
int main()
{
    printf("I lost my cellphone!");
    return 0;
}

BC32 output student information

#include <stdio.h>
int main()
{
    printf("Name    Age    Gender\n");
    printf("---------------------\n");
    printf("Jack    18     man   \n");
    return 0;
}

BC33 calculate average score

#include <stdio.h>
int main()
{
    int stu1, stu2, stu3, stu4, stu5;
    scanf("%d %d %d %d %d", &stu1, &stu2, &stu3, &stu4, &stu5);
    float stu_avg = (stu1 + stu2 +stu3 + stu4 + stu5) / 5.0;
    printf("%.1f", stu_avg);
    return 0;
}

BC34 hex A+B

#include <stdio.h>
int main()
{
    int a, b;
    scanf("%x %o", &a, &b);
    printf("%d", (a + b));
    return 0;
}

BC35 judgment letter

#include <stdio.h>
int main()
{
    char ch;
    scanf("%c", &ch);
    if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
        printf("YES");
    else
        printf("NO");
    return 0;
}

BC36 health assessment

#include <stdio.h>
int main()
{
    double Hight;
    double Weight;
    double BMI;
    scanf("%lf %lf", &Weight, &Hight);
    BMI = Weight / (Hight*Hight);
    if(BMI >= 18.5 && BMI <= 23.9)
        printf("Normal\n");
    else
        printf("Abnormal\n");
    return 0;
}

BC37 online shopping

#include <stdio.h>

typedef struct Yh
{
    float price;
    int month;
    int day;
    int flag;
}YH;

int main()
{
    YH XM = {0};
    scanf("%f %d %d %d", &XM.price, &XM.month, &XM.day, &XM.flag);
    if(XM.month == 11 && XM.day == 11)
        XM.price = XM.price * 0.7;
    else if(XM.month == 12 && XM.day == 12)
        XM.price = XM.price * 0.8;
    if(XM.flag == 1)
            XM.price = XM.price - 50;
    if(XM.price <= 0)
        XM.price = 0;
    printf("%.2f", XM.price);
    return 0;
}

BC38 variety daffodil

#include <stdio.h>
int main()
{
    int a[4];
    int b[4];
    for(int i = 10000; i <= 99999; i++)
    {
        a[0] = i / 10000;
        b[0] = i % 10000;
        a[1] = i / 1000;
        b[1] = i % 1000;
        a[2] = i / 100;
        b[2] = i % 100;
        a[3] = i / 10;
        b[3] = i % 10;
        if(i == a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3])
            printf("%d ", i);
    }
    return 0;
}

BC39 competes for the top five

#include <stdio.h>
int main()
{
    int n;
    int a[50] = {0};
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < 5; i++)
    {
         for(int j = i+1; j< n; j++)
         {
             if(a[j] > a[i])
             {
                 int tmp = a[i];
                 a[i] = a[j];
                 a[j] = tmp;
             }
         }
        printf("%d ", a[i]);
    }
}

BC40 running for president

#include <stdio.h>
int main()
{
    char ch;
    int A = 0, B = 0, E = 0;
    while((ch = getchar()) != '0')
    {
        if(ch == 'A')
            A++;
        if(ch == 'B')
            B++;
    }
    if(A == B)
    {
        printf("E\n");
        return 0;
    }
    int flag = A > B ? 0 : 1;
    if(flag == 0)
        printf("A\n");
    else
        printf("B\n");
    return 0;
}

BC41 are you a genius?

#include <stdio.h>
int main()
{
    int Genius;
    while(scanf("%d", &Genius) != EOF)
    {
        if(Genius >= 140)
            printf("Genius\n");
    }
    return 0;
}

BC42 perfect score

#include <stdio.h>
int main()
{
    int score;
    while(scanf("%d", &score) != EOF)
    {
        if(score >= 90 && score <= 100)
            printf("Perfect\n");
    }
    return 0;
}

BC43 pass score

#include <stdio.h>
int main()
{
    int score;
    while(scanf("%d", &score) != EOF)
    {
        if(score >= 60 && score <= 100)
            printf("Pass\n");
        else
            printf("Fail\n");
    }
    return 0;
}

BC44 judging integer parity

#include <stdio.h>
int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {
        if(n % 2 == 0)
            printf("Even\n");
        else
            printf("Odd\n");
    }
    return 0;
}

BC45 highest score

#include <stdio.h>
int main()
{
    int a[3] = {0};
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    int max = a[0];
    for(int i = 1; i <= 2; i++)
    {
        if(a[i] > max)
            max = a[i];
    }
    printf("%d", max);
    return 0;
}

BC46 determines whether it is a vowel or consonant

#include <stdio.h>
int main()
{
    char a[10] = {'A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u'};
    char ch;
    int flag = 0;
    while(scanf("%c", &ch) != EOF)
    {
        getchar();
        for(int i = 0; i < 10; i++)
        {
            if(ch == a[i])
                flag = 1;
        }
        if(flag == 1)
        {
            flag = 0;
            printf("Vowel\n");
        }
        else
            printf("Consonant\n");
    }
}

BC47 judge whether it is a letter

#include <stdio.h>
int main()
{
    char ch;
    while((ch = getchar()) != EOF)
    {
        getchar();
        if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
            printf("%c is an alphabet.\n", ch);
        else
            printf("%c is not an alphabet.\n", ch);
    }
    return 0;
}

BC48 letter case conversion

#include <stdio.h>
int main()
{
    char ch;
    while((ch = getchar()) != EOF)
    {
        getchar();
        if(ch >= 'a' && ch <= 'z')
            ch = ch - 32;
        else if(ch >= 'A' && ch <= 'Z')
            ch = ch + 32;
        printf("%c\n", ch);
    }
    return 0;
}

BC49 judge the size relationship between two numbers

#include <stdio.h>
int main()
{
    int a = 0, b = 0;
    while(scanf("%d %d", &a, &b) != EOF)
    {
        if(a == b)
            printf("%d=%d\n", a, b);
        else if(a > b)
            printf("%d>%d\n", a, b);
        else
            printf("%d<%d\n", a, b);
    }
    return 0;
}

BC50 calculation unit step function

#include <stdio.h>
int main()
{
    int num;
    while(scanf("%d", &num) != EOF)
    {
        if(num > 0)
            printf("1\n");
        else if(num == 0)
            printf("0.5\n");
        else
            printf("0\n");
    }
    return 0;
}

BC51 triangle judgment

#include <stdio.h>
int main()
{
    int a = 0, b = 0, c = 0;
    while(scanf("%d %d %d", &a, &b, &c) != EOF)
    {
        if(a + b > c && b + c > a && c + a > b)
        {
            if(a == b && b == c)
                printf("Equilateral triangle!\n");
            else if(a == b || b == c || c == a)
                printf("Isosceles triangle!\n");
            else
                printf("Ordinary triangle!\n");
        }
        else
            printf("Not a triangle!\n");
    }
    return 0;
}

BC52 measures the degree of obesity and thinness of the human body

#include <stdio.h>
#include <math.h>
int main()
{
    int weight = 0, high = 0;
    while(scanf("%d %d", &weight, &high) != EOF)
    {
        double BMI = weight / pow((double)high/100.0, 2.0);
        if(BMI < 18.5)
            printf("Underweight\n");
        else if(BMI >= 18.5 && BMI <= 23.9)
            printf("Normal\n");
        else if(BMI > 23.9 && BMI <= 27.9)
            printf("Overweight\n");
        else
            printf("Obese\n");
    }
    return 0;
}

BC53 calculation of univariate quadratic equation

#include <stdio.h>
#include <math.h>
int main()
{
    float a = 0, b = 0, c = 0;
    float x1 = 0, x2 = 0;
    float s = 0, x = 0;
    while(scanf("%f %f %f", &a, &b, &c) != EOF)
    {
        if(a == 0)
            printf("Not quadratic equation\n");
        else
        {
            double delat = pow(b, 2.0) - 4 * a * c;
            if(delat == 0)
            {
                x1 = (-b + sqrt(delat)) / (2 * a);
                printf("x1=x2=%.2f\n", x1);
            }
            else if(delat > 0)
            {
                x1 = (-b - sqrt(delat)) / (2 * a);
                x2 = (-b + sqrt(delat)) / (2 * a);
                printf("x1=%.2f;x2=%.2f\n", x1, x2);
            }
            else
            {
                s = -b / (2 * a);
                x = sqrt(-delat) / (2 * a);
                printf("x1=%.2f-%.2fi;x2=%.2f+%.2fi\n", s, x, s, x);
            }
        }
    }
    return 0;
}

BC54 get month days

#include <stdio.h>
int main()
{
    int a[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 
                    {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
    int flag = 0;
    int year, month;
    while(scanf("%d %d", &year, &month) != EOF)
    {
        flag = 0;
        if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
            flag = 1;
        printf("%d\n", a[flag][month - 1]);
    }
    return 0;
}

BC55 simple calculator

#include <stdio.h>
int main()
{
    double a, b;
    char ch;
    scanf("%lf%c%lf", &a, &ch, &b);
    switch(ch)
    {
        case '+':
            printf("%.4f+%.4f=%.4f\n", a, b, (a+b));
            break;
        case '-':
            printf("%.4f-%.4f=%.4f\n", a, b, (a-b));
            break;
        case '*':
            printf("%.4f*%.4f=%.4f\n", a, b, (a*b));
            break;
        case '/':
            if(b == 0)
                printf("Wrong!Division by zero!\n");
            else
                printf("%.4f/%.4f=%.4f\n", a, b, (a/b));
            break;
        default:
            printf("Invalid operation!\n");
            break;
    }
    return 0;
}

BC56 line segment pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        while(num--)
            printf("*");
        printf("\n");
    }
    return 0;
}

BC57 square pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while((scanf("%d", &num)) != EOF)
    {
        int n = num;
        while(num--)
        {
            for(int i = 0; i < n; i++)
            {
                printf("* ");
            }
            printf("\n");
        }
    }
    return 0;
}

BC58 right triangle pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = 1; i <= num; i++)
        {
            int j = i;
            while(j--)
                printf("* ");
            printf("\n");
        }
    }
    return 0;
}

BC59 flip right triangle pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = num; i >= 1; i--)
        {
            int j = i;
            while(j--)
                printf("* ");
            printf("\n");
        }
    }
    return 0;
}

BC60 right triangle with space

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = num - 1; i >= 0; i--)
        {
            int j = i;
            while(j--)
                printf("  ");
            int n = num - i;
            while(n--)
                printf("* ");
            printf("\n");
        }
    }
    return 0;
}

BC61 pyramid pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = num - 1; i >= 0; i--)
        {
            int j = i;
            while(j--)
                printf(" ");
            int n = num - i;
            while(n--)
                printf("* ");
            printf("\n");
        }
    }
    return 0;
}

BC62 flip pyramid pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = num; i > 0; i--)
        {
            for(int j = i; j < num; j++)
                printf(" ");
            int n = i;
            while(n--)
                printf("* ");
            printf("\n");
        }
    }
    return 0;
}

BC63 diamond pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int p = 1; p <= num; p++)
        {
            int mmp = num - p + 1;
                
            while(mmp--)
                printf(" ");
            int pp = p;
            while(pp--)
                printf("* ");
            printf("\n");
        }
        for(int i = num + 1 ; i > 0; i--)
        {
            for(int j = i; j < num + 1; j++)
                printf(" ");
            int n = i;
            while(n--)
                printf("* ");
            printf("\n");
        }
    }
    return 0;
}

BC64 K-shaped pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = num + 1; i > 1; i--)
        {
            int mmp = i;
            while(mmp--)
                printf("* ");
            printf("\n");
        }
        for(int i = 1; i <= num + 1; i++)
        {
            int n = i;
            while(n--)
                printf("* ");
            printf("\n");
        }
    }
    return 0;
}

BC65 arrow pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = 1; i <= num + 1; i++)
        {
            int mmp = (num - i + 1) * 2;
            for(int j = mmp; j > 0; j--)
                printf(" ");
            int nmmp = i;
            while(nmmp--)
                printf("*");
            printf("\n");
        }
        for(int i = num; i > 0; i--)
        {
            int op = (num - i + 1) * 2;
            while(op--)
                printf(" ");
            int oo = i;
            while(oo--)
                printf("*");
            printf("\n");
        }
    }
    return 0;
}

BC66 backslash pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = 0; i < num; i++)
        {
            int j = i;
            for(int j = 0; j < i; j++)
                printf(" ");
            printf("* \n");
        }
    }
    return 0;
}

BC67 slash pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = num - 1; i >= 0; i--)
        {
            int j = i;
            for(int j = 0; j < i; j++)
                printf(" ");
            printf("* \n");
        }
    }
    return 0;
}

BC68 X pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = 1; i <= num; i++)
        {
            for(int j = 1; j <= num; j++)
            {
                if(i == j || j == num - i + 1)
                    printf("*");
                else
                    printf(" ");
            }
                printf("\n");
        }
    }
    return 0;
}

BC69 hollow square pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = 1; i <= num; i++)
        {
            for(int j = 1; j <= num; j++)
            {
                if(i == 1 || i == num || j == 1 || j == num)
                    printf("* ");
                else
                    printf("  ");
            }
                printf("\n");
        }
    }
    return 0;
}

BC70 hollow triangle pattern

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = 1; i <= num; i++)
        {
            for(int j = 1; j <= num; j++)
            {
                if(j == i || j == 1 || i == num)
                    printf("* ");
                else
                    printf("  ");
            }
                printf("\n");
        }
    }
    return 0;
}

BC71 happy New Year

#include <stdio.h>
int main()
{
    printf("Happy New Year*2019*\n");
    return 0;
}

BC72 average height

#include <stdio.h>
int main()
{
    float h1, h2, h3, h4, h5;
    scanf("%f %f %f %f %f", &h1, &h2, &h3, &h4, &h5);
    printf("%.2f", (h1+h2+h3+h4+h5)/5.0);
    return 0;
}

BC73 hanging danger

#include <stdio.h>
int main()
{
    int score = 0;
    scanf("%d", &score);
    if(score >= 0 && score <= 3)
        printf("Good\n");
    else if(score >= 4 && score <= 9)
        printf("Danger\n");
    else
        printf("Danger++\n");
}

BC74 HTTP status code

#include<stdio.h>
int main()
{
    int n;
    while (scanf("%d",&n)!=EOF)
    {
       switch(n)
       {
            case 200:
               printf("OK\n");
               break;
           case 202:
               printf("Accepted\n");
               break;
           case 400:
               printf("Bad Request\n");
               break;
           case 403:
               printf("Forbidden\n");
               break;
           case 404:
               printf("Not Found\n");
               break;
           case 500:
               printf("Internal Server Error\n");
               break;
           case 502:
               printf("Bad Gateway\n");
               break;
       }
    }
    return 0;
}

BC75 digital triangle

#include <stdio.h>
int main()
{
    int num = 0;
    while(scanf("%d", &num) != EOF)
    {
        for(int i = 1; i <= num; i++)
        {
            for(int j = 1; j <= i; j++)
            {
                printf("%d ", j);
            }
            printf("\n");
        }
    }
    return 0;
}

BC76 civil service interview

#include <stdio.h>
void sort(int a[], int length);
int main()
{
    int a[7] = {0};
   while(scanf("%d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6]) != EOF)
   {
       sort(a, 7);
       printf("%.2f\n", (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6])/5.0);
   }
    return 0;
}
void sort(int a[], int length)
{
    int max = 0;
    int min = 0;
    for(int i = 1; i < 7; i++)
    {
        if(a[i] > a[max])
            max = i;
        else if(a[i] < a[min])
            min = i;
    }
    a[max] = 0;
    a[min] = 0;
}

BC77 ordered sequence inserts a number

#include <stdio.h>
int main()
{
    int m = 0, num = 0, j = 0;
    scanf("%d", &m);
    int *arr = (int *)malloc((m+1) * sizeof(int));
    for(int i = 0; i < m; i++)
        scanf("%d", &arr[i]);
    scanf("%d", &num);
    for(j = m-1; arr[j] > num && j >= 0; j--)
        arr[j+1] = arr[j];
    arr[j+1] = num;
    for(int k = 0; k < m+1; k++)
        printf("%d ", arr[k]);
    free(arr);
    return 0;
}

BC78 screening method for prime number

#include <stdio.h>
int main()
{
    int num = 0, flag = 0, cut = 0;
    scanf("%d", &num);
    for(int i = 2; i <= num; i++)
    {
        for(int j = 2; j < i; j++)
        {
            flag = 0;
            if(i % j == 0)
            {
                flag = 1;
                cut++;
                break;
            }
        }
        if(flag == 0)
        {
            printf("%d ", i);
        }
    }
    printf("\n%d\n", cut);
    return 0;
}

BC79 image similarity

#include <stdio.h>
double Get_similar(int a, int b)
{
    int *p;
    int *q;
    int i;
    int count = 0;
    p = (int*)malloc((a*b)*sizeof(int));//Open up the first picture space
    q = (int*)malloc((a*b)*sizeof(int));//Open up a second picture space
    if(q != NULL && p != NULL)
    {
        for(i = 0; i < a*b; i++)//Enter first picture
        {
            scanf("%d ", &p[i]);
         }
        for(i = 0; i < a*b; i++)//Enter second picture
        {
            scanf("%d ", &q[i]);
         }
        for(i = 0; i < a*b; i++)//If the pixels are the same, count is + 1
        {
            if(p[i] == q[i])
            {
                count++;
            }
        }
    }
    free(p);										//Remember to free up space
    free(q);
    return count*100/(double)(a*b);
}
int main()
{
    int a,b;
    double similar;
    scanf("%d %d",&a,&b);
    similar = Get_similar(a, b);
    printf("%.2f", similar);
    return 0;
}

BC80 login authentication

#include <stdio.h>
#include <string.h>
int main()
{
    char admin[10];
    char password[10];
    while(scanf("%s %s", admin, password) != EOF)
    {
        if(strcmp(admin, "admin") == 0 && strcmp(password, "admin") == 0)
            printf("Login Success!\n");
        else
            printf("Login Fail!\n");
    }
    return 0;
}

Bc81C++

#include <stdio.h>
int main()
{
    printf("I will learn C++ well!");
    return 0;
}

Calculation of BC82 (a+b-c)*d

#include <stdio.h>
int main()
{
    int a = 0, b = 0, c = 0, d = 0;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    printf("%d", (a+b-c)*d);
    return 0;
}

BC83 divisible by 5

#include <stdio.h>
int main()
{
    int n = 0;
    scanf("%d", &n);
    if(n % 5 == 0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

BC84 calculated value of y

#include <stdio.h>
int main()
{
    int x = 0;
    scanf("%d", &x);
    if(x == 0)
        printf("0\n");
    else if(x < 0)
        printf("1\n");
    else
        printf("-1\n");
    return 0;
}

BC85 contains the number 9

#include <stdio.h>

int main()
{
    int cnt = 0;
    for (int i = 1; i <= 2019; i++)
    {
        int m = i;
        while (m > 0)
        {
            if (m % 10 == 9)
            {
                cnt++;
                break;
            }
            else
            {
                m /= 10;
            }
        }
    }
    //output
    printf("%d\n", cnt);

    return 0;
}

BC86 parity statistics

#include <stdio.h>
int main()
{
    int n = 0;
    int x = 0, y = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        if(i % 2 == 0)
            y++;
        else
            x++;
    }
    printf("%d %d", x, y);
    return 0;
}

BC87 statistical results

#include <stdio.h>
int main()
{
    int n = 0, max = 0, min = 0;
    float sum = 0;
    scanf("%d", &n);
    float *arr = (float *)malloc(n * sizeof(float));
    if(arr != NULL)
    {
        for(int i = 0; i < n; i++)
        {
            scanf("%f ", &arr[i]);
            sum += arr[i];
            if(arr[i] > arr[max])
                max = i;
            if(arr[i] < arr[min])
                min = i;
        }
    }
    printf("%.2f %.2f %.2f", arr[max], arr[min], sum / n);
    free(arr);
    return 0;
}

BC88 ordered sequence inserts a number

#include <stdio.h>
int main()
{
    int m = 0, num = 0, j = 0;
    scanf("%d", &m);
    int *arr = (int *)malloc((m+1) * sizeof(int));
    for(int i = 0; i < m; i++)
        scanf("%d", &arr[i]);
    scanf("%d", &num);
    for(j = m-1; arr[j] > num && j >= 0; j--)
        arr[j+1] = arr[j];
    arr[j+1] = num;
    for(int k = 0; k < m+1; k++)
        printf("%d ", arr[k]);
    free(arr);
    return 0;
}

BC89 password authentication

#include <stdio.h>
#include <string.h>
int main()
{
    char password[20];
    char repassword[20];
    while(scanf("%s %s", password, repassword) != EOF)
    {
        if(strcmp(password, repassword) == 0)
            printf("same\n");
        else
            printf("different\n");
    }
    return 0;
}

BC90 matrix calculation

#include <stdio.h>
int main()
{
    int N, M, sum = 0;
    scanf("%d %d", &N, &M);
    int *arr = (int *)malloc(N*M*sizeof(int));
    for(int i = 0; i < N*M; i++)
    {
        scanf("%d ", &arr[i]);
        if(arr[i] > 0)
            sum += arr[i];
    }
    printf("%d", sum);
    return 0;
}

BC91 score input / output problem

#include <stdio.h>
#define N 10
int main()
{
    int a[N] = {0};
    for(int i = 0; i < 10; i++)
    {
        scanf("%d ", &a[i]);
        printf("%d ", a[i]);
    }
    return 0;
}

BC92 reverse order output

#include <stdio.h>
#define N 10
int main()
{
    int a[N] = {0};
    for(int i = 0; i < N; i++)
    {
        scanf("%d ", &a[i]);
    }
    for(int j = N - 1; j >= 0; j--)
        printf("%d ", a[j]);
    return 0;
}

BC93 positive and negative statistics

#include <stdio.h>
int main()
{
    int pos = 0, nav = 0;
    int n = 10;
    int num = 0;
    while(n--)
    {
        scanf("%d ", &num);
        if(num > 0)
            pos++;
        if(num < 0)
            nav++;
    }
    printf("positive:%d\n", pos);
    printf("negative:%d\n", nav);
    return 0;
}

Sum of BC94 N

#include <stdio.h>
int main()
{
    int N = 0, num = 0, sum = 0;
    scanf("%d", &N);
    while(N--)
    {
        scanf("%d ", &num);
        sum += num;
    }
    printf("%d\n", sum);
    return 0;
}

Difference between BC95 highest score and lowest score

#include <stdio.h>
int main()
{
    int N = 0, num = 0, max = 0, min = 100;
    scanf("%d", &N);
    while(N--)
    {
        scanf("%d ", &num);
        if(num > max) max = num;
        if(num < min) min = num;
    }
    printf("%d\n", max - min);
    return 0;
}

BC96 ordered sequence judgment

#include <stdio.h>

int main()
{
    int n = 0;
    int arr, num;
    int flag1 = 0;
    int flag2 = 0;
    //input
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &arr);
        if (i > 0)
        {
            if (arr > num)
            {
                flag1 = 1;
            }
            else if (arr < num)
            {
                flag2 = 1;
            }
        }
        num = arr;
    }
    //Ternary operator printing
    //If they are all equal, the result is 0, which is ordered
    (flag1 + flag2 > 1) ? printf("unsorted\n") : printf("sorted\n");
    return 0;
}

BC97 insert an integer into the ordered sequence

#include <stdio.h>
int main()
{
    int m = 0, num = 0, j = 0;
    scanf("%d", &m);
    int *arr = (int *)malloc((m+1) * sizeof(int));
    for(int i = 0; i < m; i++)
        scanf("%d ", &arr[i]);
    scanf("%d", &num);
    for(j = m-1; arr[j] > num && j >= 0; j--)
        arr[j+1] = arr[j];
    arr[j+1] = num;
    for(int k = 0; k < m+1; k++)
        printf("%d ", arr[k]);
    free(arr);
    return 0;
}

Deletes the specified number from the BC98 sequence

#include <stdio.h>
int main()
{
    int m = 0, num = 0, j = 0;
    scanf("%d", &m);
    int *arr = (int *)malloc(m * sizeof(int));
    for(int i = 0; i < m; i++)
        scanf("%d ", &arr[i]);
    scanf("%d", &num);
    for(j = 0; j < m; j++)
    {
        if(num != arr[j])
            printf("%d ", arr[j]);
    }
    printf("\n");
    free(arr);
    return 0;
}

Integer de duplication in BC99 sequence

#include <stdio.h>
int main()
{
    int m = 0, num = 0, flag = 0;
    scanf("%d", &m);
    int *arr = (int *)malloc(m * sizeof(int));
    for(int i = 0; i < m; i++)
        scanf("%d ", &arr[i]);
    for(int j = 0; j < m; j++)
    {
        flag = 0;
        for(int k = 0; k < j; k++)
        {
            if(arr[j] == arr[k]) flag = 1;
        }
        if(flag == 0)
            printf("%d ", arr[j]);
    }
    printf("\n");
    free(arr);
    return 0;
}

BC100 ordered sequence merging

#include <stdio.h>
int main()
{
    int N = 0, M = 0, k = 0, flag = 0;
    scanf("%d %d", &N, &M);
    int *first = (int *)malloc((N+M)*sizeof(int));
    int *second = (int *)malloc(M*sizeof(int));
    for(int i = 0; i < N; i++)
    {
        scanf("%d ", &first[i]);
    }
    for(int j = 0; j < M; j++)
    {
        scanf("%d ", &second[j]);
    }
    for(int i = 0; i < M; i++)
    {
        flag = 0;
        for(k = N - 1; k >= 0; k--)
        {
            if(first[k] > second[i]) 
            {
                first[k+1] = first[k];
                if(k == 0)
                    flag = 1;
            }
            else
            {
                first[k+1] = second[i];
                break;
            }
        }
        if(flag == 1)
            first[0] = second[i];
        N++;
    }
    for(int x = 0; x < N; x++)
    {
        printf("%d ", first[x]);
    }
    free(first);
    free(second);
    return 0;
}

BC101 class grade input and output

#include<stdio.h>
int main()
{
    double arr[5][5];
    for(int i = 0; i < 5; i++)
    {
       scanf("%lf %lf %lf %lf %lf", &arr[i][0], &arr[i][1], &arr[i][2], &arr[i][3], &arr[i][4]);
    }
    for(int i = 0; i < 5; i++)
    {
        double sum = 0;
        for(int j = 0; j < 5; j++)
        {
            printf("%.1f ", arr[i][j]);
            sum += arr[i][j];
        }
        printf("%.1f\n", sum);
    }
    return 0;
}

BC102 matrix element positioning

#include <stdio.h>
int main()
{
    int H = 0, L = 0;
    scanf("%d %d", &H, &L);
    int *arr = (int *)malloc(H*L*sizeof(int));
    for(int i = 0; i < H*L; i++)
    {
        scanf("%d ", &arr[i]);
    }
    int sH, sL;
    scanf("%d %d", &sH, &sL);
    printf("%d\n", arr[(sH-1)*L+sL-1]);
    free(arr);
}

BC103 sequence recombination matrix

#include <stdio.h>
int main()
{
    int n = 0, m = 0;
    scanf("%d %d", &n, &m);
    int *arr = (int *)malloc(n*m*sizeof(int));
    for(int i = 0; i < n*m; i++)
    {
        scanf("%d ", &arr[i]);
        if(i != 0 && i % m == 0)
            printf("\n");
        printf("%d ", arr[i]);
    }
    free(arr);
    return 0;
}

BC104 maximum height

#include <stdio.h>
int main()
{
    int N = 0, M = 0, max = 0;
    scanf("%d %d", &N, &M);
    int *arr = (int *)malloc(N*M*sizeof(int));
    for(int i = 0; i < N*M; i++)
    {
        scanf("%d ", &arr[i]);
        if(arr[i] > arr[max])
            max = i;
    }
    printf("%d %d", max/M + 1, max + 1 - (max/M)*M);
}

BC105 matrix equality determination

#include <stdio.h>
int main()
{
    int N = 0, M = 0, max = 0;
    scanf("%d %d", &N, &M);
    int *arr = (int *)malloc(N*M*sizeof(int));
    int *prr = (int *)malloc(N*M*sizeof(int));
    for(int i = 0; i < N*M; i++)
    {
        scanf("%d ", &arr[i]);
    }
    for(int i = 0; i < N*M; i++)
    {
        scanf("%d ", &prr[i]);
        if(arr[i] != prr[i])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

BC106 upper triangular matrix decision

#include <stdio.h>
int main()
{
    int n = 0, flag = 0;
    scanf("%d", &n);
    int *arr = (int *)malloc(n*n*sizeof(int));
    for(int i = 0; i < n*n; i++)
    {
        scanf("%d ", &arr[i]);
    }
    for(int x = 0; x < n; x++)
    {
        for(int y = 0; y < x; y++)
        {
            if(*(arr+x*n+y) != 0)
                flag = 1;
        }
    }
    if(flag == 1)
        printf("NO\n");
    else
        printf("YES\n");
    free(arr);
    return 0;
}

BC107 matrix transpose

#include <stdio.h>
int main()
{
    int n = 0, m = 0;
    scanf("%d %d", &n, &m);
    int *arr = (int *)malloc(n*m*sizeof(int));
    for(int i = 0; i < n*m; i++)
    {
        scanf("%d ", &arr[i]);
    }
    for(int i = 0; i < m; i++)
    {
        for(int j = 0; j < n; j++)
        {
            printf("%d ", *(arr+j*m+i));
        }
        printf("\n");
    }
    free(arr);
    return 0;
}

BC108 matrix exchange

#include <stdio.h>
int main()
{
    int n = 0, m = 0;
    scanf("%d %d", &n, &m);
    int *arr = (int *)malloc(n*m*sizeof(int));
    for(int i = 0; i < n*m; i++)
    {
        scanf("%d ", &arr[i]);
    }
    int num = 0;
    char ch;
    int h = 0, l = 0;
    scanf("%d", &num);
    while(num--)
    {
        getchar();
        scanf("%c %d %d", &ch, &h, &l);
        switch(ch)
        {
            case 'r':
                for(int i = 0; i < m; i++)
                {
                    int tmp = *(arr+(h-1)*m+i);
                    *(arr+(h-1)*m+i) = *(arr+(l-1)*m+i);
                    *(arr+(l-1)*m+i) = tmp;
                }
                break;
            case 'c':
                for(int i = 0; i < n; i++)
                {
                    int mmp = *(arr+i*m+h-1);
                    *(arr+i*m+h-1) = *(arr+i*m+l-1);
                    *(arr+i*m+l-1) = mmp;
                }
                break;
            default:
                break;
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            printf("%d ", *(arr+i*m+j));
        }
        printf("\n");
    }
    free(arr);
    return 0;
}

BC109 Yanghui triangle

#include <stdio.h>

int main()
{
    int n = 0;
    int arr[30][30] = { 0 };
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (0 == j || i == j)
            {
                arr[i][j] = 1;
            }
            else
            {
                arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
            }
            printf("%5d", arr[i][j]);
        }
        printf("\n");
    }
    return 0;
}

BC110 tic tac toe chess

#include <stdio.h>
int main()
{
    char arr[3][3] = {0};
    int i = 0;
    int j = 0;
    char flag = 'c';
    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 3; j++)
        {
            scanf("%c", &arr[i][j]);
            getchar();
        }
    }
    for(i = 0; i < 3; i++)
    {
        if(arr[i][0] == arr[i][1] && arr[i][1] == arr[i][2])
        {
            flag = arr[i][1];
            break;
        }
        if(arr[0][i] == arr[1][i] && arr[1][i] == arr[2][i])
        {
            flag = arr[1][i];
            break;
        }
    }
    if(arr[0][0] == arr[1][1] && arr[1][1] == arr[2][2])
        flag = arr[1][1];
    if(arr[0][2] == arr[1][1] && arr[1][1] == arr[2][0])
        flag = arr[1][1];
    if(flag == 'K')
        printf("KiKi wins!");
    else if(flag == 'B')
        printf("BoBo wins!");
    else
        printf("No winner!");
    return 0;
}

BC111 small Lele and binary conversion

#include <stdio.h>
int main()
{
    int n = 0;
    int m = 0;
    int a[9] = {0};
    int size = 0;
    scanf("%d", &n);
    while(n)
    {
        m = n % 6;
        a[size++] = m;
        n = n / 6;
    }
    for(int j = size-1; j >= 0; j--)
        printf("%d", a[j]);
    return 0;
}

BC112 xiaolele seeking sum

#include  <stdio.h>
int main()
{
    int n = 0;
    long sum = 0;
    scanf("%d", &n);
    while(n)
    {
        sum += n;
        n--;
    }
    printf("%ld",sum);
    return 0;
}

BC113 xiaoleloding alarm clock

#include <stdio.h>
int main()
{
    int hour = 0, min = 0;
    long after = 0;
    scanf("%d:%d %d", &hour, &min, &after);
    int all = hour * 60 + min + after;
    printf("%02d:%02d", all/60%24, all%60);
    return 0;
}

BC114 xiaolele Pai elevator

#include <stdio.h>
int main()
{
    int n = 0;
    scanf("%d", &n);
    printf("%d", (n/12)*4+2);
    return 0;
}

BC115 little Lele and Euclid

#include <stdio.h>
int main()
{
    long long n = 0;
    long long m = 0;
    scanf("%lld %lld", &n, &m);
    long long a = n;
    long long b = m;
    int t = 0;
    while (t = a % b)
    {
        a = b;
        b = t;
    }
    printf("%lld\n", b + m * n / b);
    return 0;
}

BC116 xiaolele changed to digital

#include <stdio.h>
int main()
{
    int a[9];
    int n, size = 0;
    int sum = 0;
    scanf("%d", &n);
    while(n)
    {
        int w = n % 10;
        if((w % 2) == 0)
            a[size++] = 0;
        else
            a[size++] = 1;
//         sum += a[size] * pow(10, i++);
        n = n / 10;
    }
    for(int i = size - 1; i >= 0; i--)
    {
        sum = sum*10 + a[i];
    }
    printf("%d\n", sum);
    return 0;
}

BC117 xiaolele steps

#include <stdio.h>
int fun(int n);
int main()
{
    int n = 0;
    int a[35] = {0};
    scanf("%d", &n);
//     printf("%d\n", fun(n));
    a[0] = 0;
    a[1] = 1;
    a[2] = 2;
    for(int i = 3; i <= n; i++)
        a[i] = a[i-1] + a[i-2];
    printf("%d\n", a[n]);
    return 0;
}
int fun(int n)
{
    if(n == 1) return 1;
    if(n == 2) return 2;
    return fun(n-1) + fun(n-2);
}

BC118 xiaolele and sequence

#include<stdio.h>
//Bucket sorting: give enough buckets, and count the number of input numbers in each bucket (for sorting a large amount of data)
int main()
{
    int n = 0;
    int temp = 0;
    scanf("%d", &n);
    int arr[1000005]={0};
    while(scanf("%d",&temp)!=EOF)
    {
        getchar();
        arr[temp]++;//The number corresponding to temp is put into the bucket numbered temp and appears++
    }
    for(int i=1;i<1000005;i++)
    {
//Output the number of each barrel from small to large. If it does not appear, it will not be printed
//         while(arr[i]--)
//         {
//Multiple printing
//             printf("%d ",i);
//         }
        if(arr[i])
        {//Print without multiplicity
            printf("%d ",i);
        }
    }
    return 0;
}

BC119 xiaolele and string

#include <stdio.h>
int main()
{
    char str[8000] = {0};
    int count = 0;
    scanf("%s", str);
    char * p = str;
    long long c = 0;
    long long ch = 0;
    long long chn = 0;
    while(*p)
    {
        if(*p == 'C')
            c++;
        else if(*p == 'H')
            ch+=c;
        else if(*p == 'N')
            chn += ch;
        p++;
    }
    printf("%lld\n", chn);
    return 0;
}

BC121 xiaolele learning programming

#include <stdio.h>
int main()
{
    printf("Practice makes perfect!\n");
    return 0;
}

BC122 xiaolele average score

#include <stdio.h>
int main()
{
    float a, b, c;
    scanf("%f %f %f", &a, &b, &c);
    printf("%.2f %.2f", (a+b+c), (a+b+c)/3);
    return 0;
}

BC123 maximum number of small lele

int main()
{
    int a,b,c,d,x,y;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    x = a > b ? a : b;
    y = c > d ? c : d;
    printf("%d", x > y ? x : y);
    return 0;
}

BC124 is xiaolele called a parent

#include <stdio.h>
int main ()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int x = a + b + c;
    if(x / 3 >= 60)
    {
        printf("NO");
    }
    else
    {
        printf("YES");
    }
    return 0;
}

BC125 xiaolele conversion score

#include <stdio.h>
int main()
{
    int score = 0;
    scanf("%d", &score);
    if (score >= 0 && score <= 100)
    {
        switch (score / 10)
        {
            case 10:
            case 9:
                printf("A\n");
                break;
            case 8:
                printf("B\n");
                break;
            case 7:
                printf("C\n");
                break;
            case 6:
                printf("D\n");
                break;
            case 5:
            case 4:
            case 3:
            case 2:
            case 1:
            case 0:
                printf("E\n");
                break;
        }
    }
    else
        printf("F\n");
    return 0;
}

BC126 how many parents are invited to xiaolele

#include <stdio.h>
typedef struct node
{
    float Chinese;
    float Math;
    float English;
    struct node *next;
}Node;
int main()
{
    int n = 0;
    Node *head = NULL;
    scanf("%d", &n);
    Node *tail = NULL;
    for(int i = 0; i < n; i++)
    {
        Node *tmp = (Node *)malloc(sizeof(Node));
        tmp->next = NULL;
        scanf("%f %f %f", &(tmp->Chinese), &(tmp->English), &(tmp->Math));
        if(head == NULL)
            head = tmp;
        else
            tail->next = tmp;
        tail = tmp;
    }
    Node *cur = head;
    int count = 0;
    while(cur)
    {
        if((cur->Chinese + cur->Math + cur->English) < 180.0)
            count++;
        cur = cur->next;
    }
    printf("%d\n", count);
    return 0;
}

BC127 xiaolele highest score

#include <stdio.h>
int main()
{
    int n = 0;
    scanf("%d", &n);
    int *arr = (int *)malloc(n * sizeof(int));
    int max = 0;
    for(int i = 0; i < n; i++)
    {
        scanf("%d ", &arr[i]);
        if(arr[i] > max)
            max = arr[i];
    }
    printf("%d\n", max);
    free(arr);
    return 0;
}

BC128 xiaolele calculation and summation

#include <stdio.h>
int Fac(int n);
int Fac_All(int n);
int main()
{
    int n = 0;
    scanf("%d", &n);
    int m = Fac_All(n);
    printf("%d", m);
    return 0;
}
int Fac(int n)
{
//     if(n == 1) return 1;
//     return n * Fac(n-1);
    int sum = 1;
    for(int i = n; i > 0; i--)
    {
        sum *= i;
    }
    return sum;
}
int Fac_All(int n)
{
//     if(n == 1) return 1;
//     return Fac(n) + Fac_All(n-1);
    int sum = 0;
    for(int j = n; j > 0; j--)
    {
        sum += Fac(j);
    }
    return sum;
}

BC129 xiaolele calculation function

#include <stdio.h>
int max3(int a, int b, int c)
{
//     int max = a;
//     if(b > max)
//         max = b;
//     if(c > max)
//         max = c;
//     return max;
    return (a > b ? a : b) > c ? (a > b ? a : b) : c;
}
int main()
{
    int a = 0;
    int b = 0;
    int c = 0;
    scanf("%d %d %d", &a, &b, &c);
    float m = ((float)max3(a+b, b, c) / (max3(a, b+c, c) + max3(a, b, b+c)));
    printf("%.2f\n", m);
    return 0;
}

BC130 xiaolele search number

#include <stdio.h>
int main()
{
    int n = 0;
    scanf("%d", &n);
    int *arr = (int *)malloc(n * sizeof(int));
    for(int i = 0; i < n; i++)
    {
        scanf("%d ", &arr[i]);
    }
    int m = 0, count = 0;
    scanf("%d", &m);
    for(int j = 0; j < n; j++)
    {
        if(arr[j] == m)
            count++;
    }
    printf("%d", count);
    free(arr);
    return 0;
}

Bc131 fundamentals of Kiki programming

#include <stdio.h>
int main()
{
    printf("printf(\"Hello world!\\n\");\n");
    printf("cout << \"Hello world!\" << endl;\n");
    return 0;
}

BC132 KiKi final grade

#include<stdio.h>
int main(void)
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    double result = 0.2 * a + 0.1 * b + 0.2 * c + 0.5 * d;
    printf("%.1f", result);
    return 0;
}

BC133 KiKi says blessings

#include <stdio.h>
int main ()
{
    int n;
    scanf("%d", &n);
    while(n--)
    {
        printf("Happy new year!Good luck!\n");
    }
    return 0;
}

Highest score of BC134 KiKi

#include<stdio.h> 
int main() 
{ 
    int a, b, c;
    scanf("%d %d %d",&a,&b,&c); 
    printf("%d",(a > b ? a : b) > c ? (a > b ? a : b) : c); 
    return 0;
}

BC135 KiKi calculates the number of prime numbers

#include<stdio.h>
int main()
{
    int count = 0;
    int flag = 0;
    for (int i = 100; i <= 999;i++) 
    {
        flag = 1;//The default is prime
        for (int j = 2; j < i; j++) 
        {
            if(i % j == 0) 
            {//There are numbers that can be divisible
                flag = 0;
                break;
            }
        }
        if(flag)
        {
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

BC136 KiKi de multiples integers and sorts

#include<stdio.h>
//Straight to the bucket row
int main()
{
    int arr[1001] = {0};
    int n = 0;
    int tmp = 0;
    scanf("%d",&n);
    while(scanf("%d",&tmp)!=EOF)
    {
        arr[tmp]++;
    };
    for(int i = 0; i < 1001; i++)
    {
        if(arr[i] != 0)
            printf("%d ", i);
    }
    return 0;
}

BC137 KiKi judgment upper triangular matrix

#include <stdio.h>
int main()
{
    int n = 0, flag = 0;
    scanf("%d", &n);
    int *arr = (int *)malloc(n*n*sizeof(int));
    for(int i = 0; i < n*n; i++)
    {
        scanf("%d ", &arr[i]);
    }
    for(int x = 0; x < n; x++)
    {
        for(int y = 0; y < x; y++)
        {
            if(*(arr+x*n+y) != 0)
                flag = 1;
        }
    }
    if(flag == 1)
        printf("NO\n");
    else
        printf("YES\n");
    free(arr);
    return 0;
}

BC138 KiKi structure and pointer

#include <stdio.h>
typedef struct node
{
    int data;
    struct node *next;
}Node;
void Creat(Node **head, int Legth);
int NodeLength(Node *head);
Node *Delete(Node *head, int da);
void printNode(Node *head);
int main()
{
    Node *head = NULL;
    int n = 0;
    scanf("%d", &n);
    Creat(&head, n);
    int m = 0;
    scanf("%d", &m);
    head = Delete(head, m);
    printf("%d\n", NodeLength(head));
    printNode(head);
}
void Creat(Node **head, int Legth)
{
    Node *tail = NULL;
    for(int i = 0; i < Legth; i++)
    {
        Node *tmp = (Node *)malloc(sizeof(Node));
        if(tmp != NULL)
        {
            scanf("%d ", &(tmp->data));
            tmp->next = NULL;
            if(*head == NULL)
                *head = tmp;
            else
                tail->next = tmp;
            tail = tmp;
        }
    }
}
int NodeLength(Node *head)
{
    Node *tmp = head;
    int cut = 0;
    while(tmp)
    {
        tmp = tmp->next;
        cut++;
    }
    return cut;
}
Node *Delete(Node *head, int da)
{
    Node *pre = head;
    Node *tail = head;
    while(tail)
    {
        if(tail->data == da)
        {
            Node *pd = tail;
            if(tail == head)
            {
                tail = tail->next;
                head = head->next;
            }
            else
            {
                pre->next = tail->next;
                tail = pre->next;
            }
            free(pd);
        }
        else
        {
            pre = tail;
            tail = pre->next;
        }

    }
    return head;
}
void printNode(Node *head)
{
    while(head)
    {
        printf("%d ", head->data);
        head = head->next;
    }
}

BC139 KiKi defines the electronic calendar class

#include <stdio.h> 
int main() 
{
    int year, month, day = 0; 
    scanf("%d %d %d", &year, &month, &day);
    printf("%d/%d/%d", day, month, year);
}

BC140 KiKi design class inheritance

#include<stdio.h> 
int main() 
{ 
    int a, b, d;
    double c, pi=3.14; 
    scanf("%d%d",&a,&b); 
    scanf("%lf",&c); 
    scanf("%d",&d); 
    printf("%d\n%g\n%d\n",a*b,(pi*c*c),d*d);
    return 0; 
}

Keywords: C Algorithm data structure

Added by rharter on Wed, 05 Jan 2022 21:50:50 +0200