[Title] Peking 2016 self Computer Science Summer Camp on machine exam

[Title] Peking 2016 self Computer Science Summer Camp on machine exam

A: piecewise function (NOI 1.4 programming based on the logical expression conditional branch)

Problem-solving ideas

This question is like make me play like this are not really even a simple question.

AC Code

#include<cstdio>

using namespace std;

int main()
{
    double x, y;
    scanf("%lf", &x);
    if (x >= 0 && x < 5)y = 2.5 - x;
    else if (x >= 5 && x < 10)y = 2 - 1.5*(x - 3)*(x - 3);
    else if (x >= 10 && x < 20)y = x / 2 - 1.5;
    printf("%.3lf", y);
    return 0;
}

B: word flip (NOI 1.7 programming foundation of the string)

Problem-solving ideas

Simple question, read an entire line in C gets () function, VS2017 without this function, Dev OJ and can lead.

AC Code

#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    char s[505];
    gets(s);
    int len = strlen(s);
    for (int i = 0; i < len; i++)
    {
        if (s[i] == ' ')printf(" ");
        if (s[i] == '_')continue;
        else
        {
            int wlen = 0;
            int tmp = i;
            while (s[tmp] != ' ')
            {
                wlen++; tmp++;
                if (tmp >= len) break;
            }
            for (int j = i + wlen - 1; j >= i; j--)
            {
                printf("%c", s[j]);
                s[j] = '_';
            }
        }
    }
    return 0;
}

C: repeatedly (1.8 programming foundation of the NOI multidimensional arrays)

Problem-solving ideas

Simple question, the most basic two-dimensional array.

AC Code

#include<cstdio>
#include<cstring>
int N[205][205];

int main()
{
    int m, n;//列和行 
    char s[205];
    scanf("%d", &m);
    scanf("%s", s);
    int len = strlen(s);
    n = len / m;
    int cnt = 1;
    for (int i = 0; i < n; i++)//Read row 
    {
         IF (% CNT 2 ) // odd-row-forward reading 
        {
             for ( int J = 0 ; J <m; J ++) N [I] [J] = S [m * I + J]; 
            CNT ++ ; 
        } 
        the else // even-row-reverse reading 
        {
             for ( int J = m - . 1 ; J> = 0 ; J -) N [I] [m - . 1 - J] = S [m * I + J]; 
            CNT ++ ; 
        } 
    } 
    for ( int J =0; j < m; j++)//按列输出 
    {
        for (int i = 0; i < n; i++)printf("%c", N[i][j]);
    }
    return 0;
}

G: reconstruction of binary tree

Problem-solving ideas

See binary explain in detail the topic. The core idea is very simple, you can do an array directly, based on nothing more than the result of preorder traversal of preorder recursive around substring respectively, after the last order print the value of the root node.

AC Code

#include <cstdio> 
#include <CString>
 char S1 [ 10000 ]; // preamble of storage 
char S2 [ 10000 ]; // in the program storage 

void F ( int L, int L2, int R2) // always required before and starting ends preorder traversal order to determine the root node and the left and right subtrees 
{
     IF (R2 == L2) return ; // no element of 
    char R & lt S1 = [L]; // root 
    int = LOC L2;
     the while (S2 [LOC] = R & lt!) LOC ++; // find the root node in a preorder traversal position of 
    F (L + . 1, L2, LOC); 
    F (L + + LOC . 1 - L2, LOC + . 1 , R2); // draw a picture to know where 
    the printf ( " % C " , R & lt); 
} 

int main () 
{ 
    the while ( Scanf ( " % S% S " !, S1, S2) = the EOF) 
    { 
        int len = strlen (S1); 
        F ( 0 , 0 , len); 
        the printf ( " \ n- " ); 
    } 
    return  0 ; 
}

H: jungle road

Problem-solving ideas

 

AC Code

 

Guess you like

Origin www.cnblogs.com/yun-an/p/11111865.html