09-Hash 2. Application and landing of QQ account (_PAT)

Source: Internet
Author: User

To achieve the QQ new account application and the old account landing simplified version of the function. The biggest challenge is: it is said that the current QQ number has 10 digits.

Enter the format description:

The input first gives a positive integer n (<=105), followed by an n-line instruction. The format of each line of instruction is: "Command (space) QQ number (space) password". Where the command character is "N" (represents new), it means to apply for a new QQ number, followed by the number and password of the new account; the command character "L" (representing login) means that the old account is logged in, followed by the login information. QQ number is not more than 10 digits, but greater than 1000 (it is said that QQ Mister Number is 1001) of the Integer. The password is a string that is not less than 6 bits, does not exceed 16 bits, and does not contain spaces.

Output Format Description:

For each instruction, give the appropriate information:

1 if the new application account succeeds, the output "New:ok";
2 If the number of the new application already exists, then the output "error:exist";
3 If the old account landing successful, then output "Login:ok";
4 If the old account QQ number does not exist, then output "Error:not Exist";
5 If the old account password is wrong, then output "Error:wrong PW".

Sample input and output: ordinal input and Output 1

5
L 1234567890 myQQ@qq.com
n 1234567890 myQQ@qq.com
n 1234567890 myQQ@qq.com
L 1234567890 myqq@qq
L 1234567890 myQQ@qq.com
Error:not Exist
new:ok
error:exist
error:wrong PW

Submitting Code

——————————

Just go to map on it, it's easier,

For map operation, the following will be reproduced a blog post, study.

The code is as follows.


#include <iostream>
#include <map>
#include <cstring>
using namespace std;

/* Run this program using the console Pauser or add your own getch, System ("pause") or input loop */



int main (int argc , char** argv) {
	int N;
	Map<string, String> MP;
	cin>>n;
	string S1,s2,s3;
	for (int i=0; i<n; i++)
	{
		cin>>s1>>s2>>s3;
		if (s1== "N")
		{
			if (mp.find (S2) ==mp.end ())
			{
				Mp.insert (Make_pair (S2,S3));
				printf ("new:ok\n");
			}
			else
			{
				printf ("error:exist\n");
			}
		}
		else if (s1== "L")
		{
			if (mp.find (S2) ==mp.end ())
			{
				printf ("Error:not exist\n");
			}
			else//exists
			{
				map<string,string>::iterator it=mp.find (S2);
				if (It->second = = S3)
				{
					printf ("login:ok\n");
				}
				else
				{
					printf ("Error:wrong pw\n");
	
	
	
	}}} return 0;
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.