QQ account application

7-1 QQ application and login account (30 point (s))
 

QQ achieve new account applications and a simplified version of the old account login function. The biggest challenge is: It is said that QQ number has 10 digits of.

Input formats:

Firstly, input a positive integer N ( ≤), and then gives N-line instructions. Each command format is: "command (blanks) QQ number (blank) password." He said to be a new application number a QQ, followed by the new account number and password which command character is "N" (on behalf of New); command symbol to "L" (on behalf of Login) when the representation is old account login, followed login information . A QQ number is not more than 10, but greater than 1000 (said boss QQ number 1001) integer. Password is not less than 6, no more than 16, the string does not include spaces.

Output formats:

For each instruction, the corresponding information is given:

1) If the new application account is successful, the output "New: the OK";
2) number if the new application already exists, then the output "ERROR: Exist";
3) If the old account login is successful, the output "Login: OK";
4) If the old QQ account number does not exist, then the output "eRROR: not exist";
5) If the old account password is wrong, the output "eRROR: wrong PW".

Sample input:

5
L 1234567890 [email protected]
N 1234567890 [email protected]
N 1234567890 [email protected]
L 1234567890 myQQ@qq
L 1234567890 [email protected]

Sample output:

ERROR: Not Exist
New: OK
ERROR: Exist
ERROR: Wrong PW
Login: OK

Since this weekend thing is a bit much, this blog also wrote some hasty, we thought of writing his thoughts on QQ account application of it.

First saw this question I started analysis of what this question is actually very simple, it is a simple comparison to determine, first of all based on the identity of the object is old account, then it is determined whether there is, if there is to determine whether the password is right. If you are a new user is determined whether or not there on it. So I started not to consider the amount of data problem, use the simple and relatively simple data type string. But no doubt is certainly not you, so I made reference to it on the use of the map. In simple terms map is to provide a container the keywords and values ​​connected. Look at an example:

enumMap[2] = "Two"; 

When you insert 2, first look at enumMap primary key for the item 2, did not find, and then insert a new object enumMap, the key is 2, the value is an empty string, the string is inserted completed, will assign to "Two"; this method will ode each value is the default, and then display the values ​​assigned. We are using when looking map in the find function find (), the function returns an iterator to key into key elements, if not found returns an iterator pointing to the tail of the map.

map<int ,string >::iterator l_it;; 

l_it=maplive.find(112); 

if(l_it==maplive.end()) 

cout<<"we do not find 112"<<endl; 

else cout << "wo find 112" << endl;
use the map function can solve the problem you ask.

#include <the iostream> 
#include <Map>
 the using  namespace STD; 
typedef struct 
{ // definition of each account information qq 
    String NUM; // Since a 10-digit account number qq 
    String PS; 
} qq; 
qq A [ 100005 ];
 int main () 
{ 
    Map < String , String > COM;
     // the associated account and password 
    int n-; 
    CIN >> n-;
     char Level;
     for ( int I = 0 ; I <n-; I ++) 
    { // individually input and output 
        CIN >> Level;
         IF (Level == ' N ' ) 
        { // If a new user 
            >> A [I] .num CIN >> A [I] .ps;
             IF ( com.find (A [I] .num) == com.end ()) 
            { // Analyzing the account does not exist 
                [A [I] .num] = A [I] COM .ps; // the new account and the password associated 
                cout << " new: the OK " << endl; 
            } 
            the else 
            { // Analyzing new user account already exists 
                cout <<"ERROR: Exist A " << endl; 
            } 
            
        } 
        the else  IF (Level == ' L ' ) 
        { // If the old user 
            CIN >> A [I] .num >> A [I] .ps;
             IF (com.find (a [I] .num) == com.end ()) 
            { // if the old user does not exist 
                COUT << " ERROR: not exist a " << endl; 
            } 
            the else 
            { // If the password associated with the account password equal 
                IF ([A [I] .num] COM == A [I] .ps) 
                COUT <<" The Login: the OK " << endl;
                 the else COUT << " ERROR: Wrong the PW " << endl; // password is not equal 
            } 
        } 
    } 
    return  0 ; 
}

About Chapter VII we learned about finding relevant knowledge, there are sentinel method based on linear lookup tables, binary search. According search tree table, first binary sort tree, to solve the problem of tree time efficiency binary sort it cited the balanced binary tree, in order to solve the amount of data issues and the introduction of B-tree, in order to achieve the range Find the introduction of the B + tree. The second problem is to find large pieces of the hash table, the characteristics of the hash table is the storage location for keywords related records associated, this method is the use of a hash function, the hash function construction method of digital analysis to take in the square but the most commonly used method, etc. in addition I stay still, at the time of settlement of the conflict there in an open address method of linear probing method, the second detection method, a pseudorandom detection method; chain address law is the use of a structure before school an array of data structures.

The chapter on before a majority of the exercises less, I hope the next chapter of the study may have more time to practice.

Guess you like

Origin www.cnblogs.com/jingjing1234/p/10964098.html