Re-examination of Central South University in 2014

2014 Central South University retest machine test

Question 1: Conversion of grades

Title description:

A grade selection system is implemented for the high school entrance examination in a certain area, and for this purpose, it is necessary to convert the scores of the corresponding subjects into the corresponding grades. Assuming that the
total score of the course is 120 points, according to the exam situation, the marking of each level is as follows:
108~120 is A;
100~107 is B;
80~99 is C;
72~79 is D;
0~71 is E ; There
are multiple groups of input data, each group occupies one line and consists of an integer.
For each set of input data, one line is output.
If the input data is not in the range of 0~120, please output a line: "Score is error!".

Input and output format:

Input:
56
67
100
123
Output
E
E
B
Score is error!

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
    int gread;
    while(scanf("%d",&gread)!=EOF){
    
    
        if(gread>=108&&gread<=120) printf("A\n");
        else if(gread>=100&&gread<=107) printf("B\n");
        else if(gread>=80&&gread<=99) printf("C\n");
        else if(gread>=72&&gread<=79) printf("D\n");
        else  if(gread>=0&&gread<=71) printf("E\n");
        else printf("Score is error!\n");
    }
    return 0;
}

Second question: sum of squares and sum of cubes

Title description:

Given a continuous integer between n and m (including n and m), find the sum of squares of all the even numbers and the sum of cubes of all odd numbers.
The input data contains multiple sets of test instances, each set of test instances contains one line, two integers m and n (0 <= n<= 10000, 0 <= m <= 10000)
For each set of input data, one line of output should include two The integers x and y respectively represent the sum of squares of all even numbers and the sum of cubes of all odd numbers in the segment of consecutive integers.

Input and output format:

Input:
1 3
2 5
Output
4 28
20 152

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF){
    
    
        long long x=0,y=0;
        for(int i=n;i<=m;i++){
    
    
            if(i%2==0) 
                x+=i*i;
            else y+=i*i*i;
        }
        printf("%lld %lld\n",x,y);
    }
    return 0;
}

Question 3: Deciphering the password

Title description:

It is said that the earliest code comes from the Roman Emperor Caesar. The method of message encryption is to replace each letter in the original message with the fifth letter after the letter (for example: each letter A in the original message is replaced with a letter F). And you want to get the original text of the message, that is, you want to reverse this process.
Password letter: ABCDEFGHIJKLMNOPQRSTU VWXYZ
original letter: VWXYZABCDEFGHIJKLMNOP QRSTU
(Note: Only letters will be replaced, other non-letter characters remain unchanged, and all letters of the original message are capitalized.) There
are no more than 100 data sets, each There will be no blank lines between the data sets. Each data set consists of 3 parts:
Start line: START
password message: 1 to 200 characters form a line, indicating a message sent by Caesar.
End line: END
at the last After the data set, there is another row: ENDOFINPUT.
Each data set corresponds to one row, which is Caesar's original message.

Input and output format:

输入:
START
NS BFW, JAJSYX TK NRUTWYFSHJ BOTTLES YMJ WJXZQY TK YWNANFQ HFZXJX
END
START
N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ
END
START
IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ
END
ENDOFINPUT

输出
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME
DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
    char a[201];
    char temp[15];
    scanf("%s",temp);
    getchar();
    while(strcmp(temp,"ENDOF INPUT")){
    
    
        gets(a);
        getchar();
        for(int i=0;i<strlen(a);i++){
    
    
            if((a[i]>64)&&(a[i]<=69))
                a[i]=(char)(a[i]+21);
             else if(a[i]>69&&a[i]<=90)
                a[i]=(char)(a[i]-5);
            else 
                a[i]=a[i];
        }
        scanf("%s",temp);
        printf("%s\n",a);
        scanf("%s",temp);
        getchar();
    }
    return 0;
}

Fourth question: the largest continuous subsequence

Title description:

Given a sequence {N1, N2, …, NK} of K integers, any continuous subsequence can be expressed as {Ni, Ni+1,…,Nj}, where 1 <= i<= j <= K. The largest continuous subsequence is the largest sum of elements in all continuous subsequences. For example, for a given sequence {-2, 11, -4, 13, -5, -2}, the largest continuous subsequence is {11, -4, 13}, the maximum sum is 20. Write a program to get the sum of the largest subsequence and output the subscripts of the first and last elements of the subsequence.
The test input contains several test cases, each test case occupies 2 lines, the first line gives a positive integer K (<100000), the second line gives K integers, the range of each integer is -10000 to 10000, with a space in between Separated.
For each test case, output the subscripts of the first and last elements of the largest sum and largest continuous subsequence in one line, separated by spaces. If the largest continuous subsequence is not unique, output the one with the smallest sequence numbers i and j (such as the second and third groups of the input sample). If all K elements are negative numbers, the maximum sum is defined as 0, and "0 0 0" is output.

Input and output format:

Input:
8
6 -2 11 -4 13 -5 -2 10
20
-10 1 2 3 4 -5 -23 3 7 -21 6 5 -8 3 2 5 0 1 10 3
8
-1 -5 -2 3- 1 0 -2 0
4
-1 -2 -4 -3

Output
27 0 7
27 10 19
3 3 3
0 0 0

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
    int n;
    long long a[10000+100],b[100000+100];
    while(scanf("%d",&n)!=EOF){
    
    
        for(int i=0;i<n;i++)
            scanf("%lld",&a[i]);
            b[0]=a[0];
            for(int i=1;i<n;i++)
                b[i]=b[i-1]+a[i];
            long long min_v=0,max_v=0;
            int min_p=-1,max_l=0,max_r=0;
            for(int i=0;i<n;i++){
    
    
                if(b[i]<min_v){
    
    
                    min_v=b[i];
                    min_p=i;
                }
                if(b[i]-min_v>max_v){
    
    
                    max_v=b[i]-min_v;
                    max_l=min_p+1;
                    max_r=i;
                }
            }
            printf("%lld %d %d\n",max_v,max_l,max_r);
    }
    return 0;
}

Fifth question: safe path

Title description:

Wesley’s novels often mention aliens, such as the Blue Blood. There are many cities in Saturn, and there are one or more flight paths between each city, but not all roads are very safe. Each road has a safety factor s, s is a real number between 0 and 1. (Including 0, 1), the safety of a channel P from u to v is Safe§ = s(e1)*s(e2)... s(ek) e1, e2, ek are the edges on P, now blue blood People want to travel, facing so many roads, he wants to find the safest way. But the mathematics of the blue blood is not good, I would like to ask you for help_ -the
input includes multiple test examples, each example includes: the
first line: an integer n. n represents the number of cities n<=1000;
then a
matrix of n n represents the safety factor between the two cities, (0 can be understood as there is no direct passage between the two cities).
Then there is an integer m (m<=100) that represents several blue-blooded people's routes to travel. There are two numbers in each row below, which represent the city where the blue-blooded person is and the city to go to.
If the blue blood person cannot reach his destination, output "What a pity!",
and output the safety factor of the safest road between the two cities, with three decimal places.

Input and output format:

Input:
3
1 0.5 0.5
0.5 1 0.4
0.5 0.4 1
3
1 2
2 3
1 3

Output
0.500
0.400
0.500

#include<bits/stdc++.h>
using namespace std;
int n,m,s,t;
const int N=1005;
double g[N][N],dist[N];
bool st[N];
void dijkstra(int s,int t){
    
    
    memset(dist,0x3f,sizeof(dist));
    for(int i=1;i<=n;i++){
    
    
        st[i]=0;
        dist[i]=g[s][i];
    }
    for(int i=1;i<n;i++){
    
    
        int t=-1;
        for(int j=1;j<=n;j++){
    
    
            if(!st[j]&&(t==-1||dist[t]<dist[j]))
                t=j;
        }
        for(int j=1;j<=n;j++){
    
    
            dist[j]=max(dist[j],dist[t]*g[t][j]);
        }
        st[t]=1;
    }
    if(dist[n]==0x3f3f3f3f) 
        printf("What a pity!\n");
    else
        printf("%.3lf\n",dist[t]);
}
int main(){
    
    
    while (scanf("%d",&n)!=EOF){
    
    
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                scanf("%lf",&g[i][j]);
            scanf("%d",&m);
            while(m--){
    
    
                scanf("%d%d",&s,&t);
                dijkstra(s,t);
        }
    }    
    return 0;
}

Happy time is always short, let's see you next time! ! !

good good study,day day up! (study hard, improve every day)

Foresee the funeral, please listen to the decomposition next time! ! ! !

Guess you like

Origin blog.csdn.net/qq_41606378/article/details/113729475