[Record] Niuke OJ-Niuke Programming Language Practice Game 1

A ASCII code

Title description

BoBo teaches that characters represented by KiKi character constants or character variables are stored in the form of ASCII codes in memory. BoBo has a problem with KiKi, convert the following ASCII codes into corresponding characters and output them.

73, 32, 99, 97, 110, 32, 100, 111, 32, 105, 116 , 33

Enter description:

no

Output description:

Convert all ASCII given in the output title to the corresponding characters.

#include<stdio.h>
int main ()
{
    int a[12];
    a[0]=73;
    a[1]=32;
    a[2]=99;
    a[3]=97;
    a[4]=110;
    a[5]=32;
    a[6]=100;
    a[7]=111;
    a[8]=32;
    a[9]=105;
    a[10]=116;
    a[11]=33;
    for(int i =0;i<=11;i++){
        printf("%c",a[i]);
    }
    printf("\n");
    return 0;
    }

B How many seconds can you live

 

#Topic description

 Question: There are about 3.156×107s in a year. You are required to enter your age and display how many seconds it is.

 

Enter description:

One line, including an integer age (0<age<=200).

Output description:

One line, containing an integer, output the number of seconds corresponding to the age.

Example 1

enter

20

Output

631200000

#include "stdio.h"
int main ()
{
    int year = 0;
    long long second=0;
    scanf("%d",&year);
    second = 3.156e7*year;
    printf("%ld",second);

    return 0;
}

C 2 to the nth power calculation

Title description

On the basis of not using cumulative multiplication, the calculation of the n-th power of 2 is realized through the shift operation (<<).

Enter description:

Multiple input, each line input integer n (0 <= n <31).

Output description:

For each group of input and output, the corresponding 2 n-th power result.

Example 1

enter

2

10

Output

4

1024

Shift operation in C language https://blog.csdn.net/frank_jb/article/details/97282161
"<<" Usage: 
The format is: a<<m, a and m must be integer expressions, and m>=0 is required. 
Function: Move the integer a to the left by m bits according to the binary digit, after the high bit is shifted out, the low bit is filled with 0. 
">>" usage: 
The format is: a>>m, a and m must be integer expressions, and m>=0 is required. 
Function: Move the integer a to the right by m bits according to the binary bit, after the low bit is shifted out, the high bit is filled with 0
#include<iostream>
int main ()
{
    using namespace std;
    unsigned long i=1;
    int n = 0;
    while (cin >> n ){
        cout<< (i<<n)<<endl;
    }
    return 0;
}

D passing score

Link: https://ac.nowcoder.com/acm/contest/5904/D

Source: Niuke.com

 

Title description

KiKi wants to know whether his test score passed, please help him judge. Enter a score represented by an integer from the keyboard, and program to determine whether the score is within the pass range. If it passes, that is, if the score is greater than or equal to 60 points, output "Pass", otherwise, output "Fail".

Enter description:

Multiple sets of input, each line of input includes a score represented by an integer (0~100).

Output description:

For each line of input, output "Pass" or "Fail".

#include<iostream>
int main ()
{
    using namespace std;
    unsigned grade;
    while ( cin >> grade)
    {
        if (grade < 60) cout << "Fail"<<endl;
        if (grade >= 60 && grade <=100) cout << "Pass" << endl;
        if (grade > 100)
        {
            cerr << "error!"<<endl;
            return -1;
        }
    }
    return 0;
}

E Determine the relationship between two numbers

Title description

KiKi wants to know the relationship between the two numbers entered from the keyboard, please program it.

Enter description:

There are multiple sets of input data for the question. Enter two integers (range (1 ~ 231-1) in each line, separated by spaces.

Output description:

For each line of input, output two integers and their size relationship. There is no space between the number and the relational operator. See the input and output sample for details.

Example 1

enter

1 1

Output

1=1

Example 2

enter

1 0

Output

1>0

Example 3

enter

0 1

Output

0<1

#include<iostream>
int main ()
{
    using namespace std;
    long long int i1,i2;
    while (cin >> i1 >>i2)
    {
        if (i1 == i2) cout << i1 << "=" << i2 << endl;
        if (i1 < i2 ) cout << i1 << "<" << i2 << endl;
        if (i1 > i2 ) cout << i1 << ">" << i2 << endl;
    }
    return 0;
}

F Health Assessment

Title description

The BMI index (ie, body mass index) is a number obtained by dividing the weight in kilograms by the height in meters squared. It is currently a commonly used international standard to measure the degree of body weight and health. For example: a person's height is 1.75 meters, weight is 68 kg, his BMI=68/(1.75^2)=22.2 (kg/m^2). When the BMI index is 18.5-23.9, it is normal, otherwise it means that the body has health risks. Program to judge human health.

Enter description:

Enter a person's weight (kg) and height (m) on one line, separated by a space.

Output description:

One line, output the body Normal (normal) or Abnormal (abnormal).

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

G flip right triangle pattern

Title description

KiKi learned the cycle. Teacher BoBo gave him a series of pattern printing exercises. This task is to print the flip right triangle pattern composed of "*".

Enter description:

Multiple sets of input, an integer (2~20), represents the length of the right-angle side of the flipped right-angled triangle, that is, the number of "*", and also the number of output lines.

Output description:

For each line of input, the output is a flipped right-angled triangle of corresponding length composed of "*", with a space after each "*".

image.png

#include<iostream>
int main ()
{
    using namespace std;
    int n;
    while(cin >> n)
    {
    for (int a = n; a > 0; a--)
    {
        int i = a;
        for (int b = i; b > 0; b--)
        {
            cout << "* ";
        }
        cout << endl;
    }
    }
    return 0;
}

H Number of positive and negative statistics

image.png

#include<iostream>
int main ()
{
    using namespace std;
    long long int a[10];
    for (int i = 0; i < 10;i++)
    {
        cin >> a[i];
    }
    int positive = 0, negative = 0;
    for (int i = 0; i < 10;i++)
    {
        if(a[i]>0)
        {
            positive++;
        }
        if(a[i]<0)
        {
            negative++;
        }
    }
    cout << "positive:" << positive << endl
         << "negative:" << negative << endl;
    return 0;
}

I matrix equality judgment

image.png

#include<iostream>
int main ()
{
    using namespace std;
    long long int n, m;
    cin >> n >> m;
    int matrix1[n][m];
    int matrix2[n][m];
    int FCheck = 0;
    for (int a = 0; a < n;a++)
    {
        for (int b = 0; b < m; b++)
        {
            cin >> matrix1[a][b];
        }
    }
    for (int a = 0; a < n;a++)
    {
        for (int b = 0; b < m; b++)
        {
            cin >> matrix2[a][b];
        }
    }
    for (int a = 0; a < n;a++)
    {
        //int FCheck = 0;
        for (int b = 0; b < m; b++)
        {
            if (matrix1[a][b] != matrix2[a][b])
            {
                FCheck++;
                cout << "No" << endl;
                return 0;
            } 
        }
    }
    if (FCheck == 0)
    {
        cout << "Yes" << endl;
    }

        return 0;
}

Guess you like

Origin blog.csdn.net/qq_31714533/article/details/109263637