Data Structures and Algorithms7-27——QQ Account Management

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

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

题目描述:

知识点: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++解题报告:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值