2012 Blue Bridge Cup

password generator

When setting passwords for important permissions such as bank accounts, we often encounter such troubles: if you use your birthday to remember your birthday, it is easy to be cracked and unsafe; if you set a password that is not easy to remember, you are worried that you will forget it too; If you write on paper, worry about the paper being found or lost ...

The task of this program is to convert a string of pinyin letters into 6 -digit numbers (passwords). We can use any easy-to-remember pinyin string ( such as the name, Wang Ximing, just write: wangximing) as input, and the program outputs a 6 -digit number.

The transformation process is as follows:

The first step .  Fold the strings in groups of 6 , for example, wangximing becomes:

wangxi

ming

Step 2. Add  the ascii code values ​​of all the characters vertically in the same position to get 6 numbers, as in the above example, get:

228 202 220 206 120 105

The third step "Abbreviated" processing of each number: that is, adding the numbers of each digit. If the obtained number is not a digit, it will be abbreviated again until it becomes a digit. Example : 228 => 2+2+8=12 => 1+2=3

The above number becomes: 344836 after abbreviated,  this is the final output of the program!

The program is required to receive data from standard input and output results on standard output.

The input format is: the first line is an integer n ( <100 ), indicating how many input lines there are below, followed by n lines of strings, which are the strings waiting to be transformed.

The output format is: n lines of transformed 6 -digit password.

For example, enter:

5

zhangfeng

wangximing

jijingfazi

woaibeijingtiananmen

haohaoxuexi

then output:

772243

344836

297332

716652

875843

answer:

I don't know if it's right or wrong, but it feels good;

Code:

#include <cstdio>
#include <iostream>
#include<string.h>
using namespace std;
int ps[6];
char str[110];
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        scanf("%s",str);
        memset(ps,0,sizeof(ps));
        for(int i=0;str[i];i++){
            ps[i%6]+=str[i];
        }
        for(int i=0;i<6;i++){
            int temp;
            while(ps[i]>9){
                temp=0;
                while(ps[i]){
                    temp+=ps[i]%10;
                    ps [i] / = 10 ;
                }
                ps[i]=temp;
            }
        }
        for(int i=0;i<6;i++)printf("%d",ps[i]);puts("");
    }
    return 0;
}

 

Probability of winning

Football matches have a certain degree of contingency, and the weak team has the possibility to defeat the strong team.

Suppose there are four teams A, B, C, and D. Based on their past games results, come up with a table of probabilities for each team to win against the other :

      A B C D

A - 0.1 0.3 0.5

B 0.9 - 0.7 0.4

C 0.7 0.3 - 0.2

D 0.5 0.6 0.8 -

Data meaning: the winning probability of A vs. B is 0.1 , the winning probability of C vs. B is 0.3 , ...

There's a tournament going on now. The two sides drew lots, divided into two groups, and the two winning teams competed for the championship. (See 【1.jpg 】)

Please run 100,000 simulations to calculate the probability of Team A winning the championship.

Notice:

Please debug carefully! Your program will only get a chance to score if it runs correctly!

The input data used in marking the paper may be different from the example data given in the test paper.

Please write all the functions in the same file, after debugging, save it in the " answer.txt " corresponding to the question number under the [examiner folder] .

Do not copy in relevant project files.

Source code must not use APIs such as drawing, Win32API , interrupt calls, hardware manipulation, or OS-related APIs .

STL class libraries are allowed , but non- ANSI C++ standard class libraries such as MFC or ATL cannot be used. For example, the CString type (which belongs to the MFC class library) cannot be used.

Solution: Consider the battle situation separately; find the probability and divide by the number of times;

Code:

 

#include<stdio.h>
#include<time.h>
#include<stdlib.h>

int main(){
    double t[3];
    t[0]=0.1*0.3*0.2+0.1*0.5*0.8;
    t[1]=0.3*0.5*0.6+0.3*0.1*0.4;
    t[2]=0.5*0.3*0.3+0.5*0.1*0.7;
    srand(time(0));
    double ans=0;
    for(int i=1;i<=100000;i++){
        int x=rand()%3;
        years += t[x];
    }
    printf("%lf\n",ans/100000);
    return 0;
}

 

ball game

There are n balls in the box. A and B take turns to take balls from the box. Everyone can see how many balls the other has taken and how many are left in the box. They're all smart and don't make wrong judgments.

We agree:

The number of balls each person takes from the box must be: 1 , 3 , 7 or 8 .

You can't abstain when it's your turn to take the ball!

A takes the ball first, then alternately takes the ball until it is finished.

The side forced to get the last ball is the loser (lose side)

Please program to determine whether A can win for a given initial number of balls without either side judging wrongly ?

When the program runs, it gets data from standard input in the following format:

The first is an integer n (n<100) , which means that there are n integers next. Then there are n integers, each on a line (integer < 10000 ), representing the initial number of balls.

The program outputs n lines, indicating the winning or losing of A ( 0 for loss and 1 for win ).

For example, the user enters:

10

18

Then the program should output:

0

1

1

0

Solution: It is good to find the sure-win point from the sure-defeat point;

Code:

#include<stdio.h>
const int MAXN=10010;
int step[4]={
    1,3,7,8};
int a[MAXN];
int main(){
    
    a[1]=0;
    for(int i=1;i<MAXN;i++){
        if(!a[i])
        for(int j=0;j<4;j++){
            a[i+step[j]]=1;
        }
    }
    int T;
    scanf("%d",&T);
    while(T--){
        int x;
        scanf("%d",&x);
        printf("%d\n",a[x]);
    }
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325650807&siteId=291194637