我的Data Structures and Algorithms代码仓:https://github.com/617076674/Data-Structures-and-Algorithms

原题链接:https://pintia.cn/problem-sets/16/problems/689

题目描述:

Data Structures and Algorithms7-27——QQ Account Management

知识点:map集合的应用

思路:用一个map存储账户信息,键为QQ号码,对应的值为密码

用long long型变量读取QQ号码,用char数组存储字符串信息。

注意char数组的存储方式,需要用strcmp函数拷贝一份存储进map集合里,不能直接存储其地址Password

C++代码:

#include<iostream>
#include<map>
#include<cstring>

using namespace std;

int N;
char Command[2];
long long QQ_No;
map<long long, char[17]> accounts;	//注意字符串的存储方式 

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		char Password[17];
		scanf("%s %lld %s", Command, &QQ_No, Password);
		if(Command[0] == 'R'){
			if(accounts.find(QQ_No) != accounts.end()){
				printf("ERROR: Account Number Already Exists\n");
			}else{
				printf("Register Successful\n");
				strcpy(accounts[QQ_No], Password);	//将Password复制一份进accounts[QQ_No] 
			}
		}else if(Command[0] == 'L'){
			if(accounts.find(QQ_No) != accounts.end()){
				if(strcmp(accounts[QQ_No], Password) == 0){
					printf("Log in Successful\n");
				}else{
					printf("ERROR: Wrong Password\n");
				}
			}else{
				printf("ERROR: Account Not Exist\n");
			}
		}
	}
	return 0;
}

C++解题报告:

Data Structures and Algorithms7-27——QQ Account Management

 

相关文章:

  • 2021-06-07
  • 2021-11-28
  • 2021-09-22
  • 2022-02-22
  • 2022-12-23
  • 2022-01-08
  • 2022-02-23
  • 2022-12-23
猜你喜欢
  • 2021-05-11
  • 2021-04-30
  • 2022-12-23
  • 2021-08-15
  • 2021-11-14
  • 2022-02-01
相关资源
相似解决方案