PTA QQ Account Manageme【map的巧妙应有】
5-27 QQ Account Management (25分)
You are supposed to implement the functions of account “Log in” and “Register” for the most popular instant messager QQ. The most challenging part is that QQ now has more than a billion users.
Input Specification:
Each input file contains one test case. For each case, the first line contains an integer N (≤105\le 10^5≤10
5
) - the total number of queries. Then N lines follow, each contains a query in the format Command QQ_No Password where Command is either R (meaning to register a new account, and hence followed by a new account number and a password), or L (meaning to log in with an existing account, and hence followed by the account number and the password); QQ_No is an integer that is greater than 1000 and no more than 10 digits long; and Password is a string with no less than 6 and no more than 16 characters without any space.
Output Specification:
For each test case, print the corresponding message for each query in a line. The messages are:
•If a new account is successfully registered, output “Register Successful”;
•If the new registering account number already exists, output “ERROR: Account Number Already Exists”;
•If log in successfully, output “Log in Successful”;
•If the log in account does not exist, output “ERROR: Account Not Exist”;
•If log in with a wrong password, output “ERROR: Wrong Password”.
Sample Input:
5
L 1234567890 myQQ@qq.com
R 1234567890 myQQ@qq.com
R 1234567890 myQQ@qq.com
L 1234567890 myQQ@qq
L 1234567890 myQQ@qq.com
Sample Output:
ERROR: Account Not Exist
Register Successful
ERROR: Account Number Already Exists
ERROR: Wrong Password
Log in Successful
这是队友的巧用map
用一个数组记录编号,然后编号映射到输入的i,输入的邮箱直接是用二位数组记录的,然后数组记录的编号映射到的 i ,直接是二维数组中的 i ,非常棒。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
const double eps=1e-5;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
#define MAX 100010
int n,m;
char c1;
char pass[MAX][21];
ll a[MAX];
int main()
{
map < ll, int >q;
int t,i,j,k;
scanf("%d",&n);
getchar();
int num1=0;
for(i=1; i<=n; i++)
{
ll b;
int flag=0;
scanf("%c",&c1);
scanf("%lld%s",&a[i],pass[i]);
getchar();
if(c1=='R')
{
if(q[a[i]]>0)
printf("ERROR: Account Number Already Exists\n");
else
{
printf("Register Successful\n");
q[a[i]]=i;
}
}
if(c1=='L')
{
if(a[q[a[i]]]==a[i])
{
if(strcmp(pass[q[a[i]]],pass[i])==0)
printf("Log in Successful\n");
else
printf("ERROR: Wrong Password\n");
}
else if(a[q[a[i]]]==0)
printf("ERROR: Account No`
Exist\n");
}
}
return 0;
}
PTA QQ Account Manageme【map的巧妙应有】的更多相关文章
- QQ现状深度剖析:你还认为QQ已经被微信打败了吗?
本文来自“人人都是产品经理”公众号作者栗栗粥的原创分享. 1.前言 移动端的时代里,微信占据了社交领域的半壁江山,不得不让人想起曾经PC时代里的王者“QQ”,微信的爆发和QQ的停滞让很多人认为微信 ...
- java基础50 配置文件类(Properties)
1. 配置文件类Properties的概念 主要生产配置文件与读取配置文件的信息 2.Properties要注意的细节 1.如果配置文件一旦使用了中文,那么在使用store方法生产的配置文件额时候字符 ...
- Python与数据库[2] -> 关系对象映射/ORM[5] -> 利用 sqlalchemy 实现关系表查询功能
利用 sqlalchemy 实现关系表查询功能 下面的例子将完成一个通过关系表进行查询的功能,示例中的数据表均在MySQL中建立,建立过程可以使用 SQL 命令或编写 Python 适配器完成. 示例 ...
- DS博客作业07——查找
1.本周学习总结 1.1思维导图 1.2.谈谈你对查找运算的认识及学习体会. 查找的内容和前两章树和图相比,要简单许多,在二次搜索树虽然也要用到树,但是也是很简单的树的操作,再加上查找的代码可以使用m ...
- python 多线程,tthread模块比较底层,而threading模块是对thread做了一些包装,multithreading
Python多线程详解 2016/05/10 · 基础知识 · 1 评论· 多线程 分享到:20 本文作者: 伯乐在线 - 王海波 .未经作者许可,禁止转载!欢迎加入伯乐在线 专栏作者. 1.多线程的 ...
- Spring MVC学习
SpringMVC框架 转载请注明出处 目录 一:配置springMVC开发环境 1.1.配置文件的helloworld 1.2.基于注解的helloworld 二:@RequestMapping详解 ...
- RedisUtil 工具类
package com.test; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import red ...
- 跟我一起数据挖掘(21)——redis
什么是Redis Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发工 ...
- iOS开发之功能模块--本地序列化
下面只展示项目开发中,本地序列化的示例代码: AuthenticationManager.h #import <Foundation/Foundation.h> #import " ...
随机推荐
- POJ - 1062 昂贵的聘礼(最短路Dijkstra)
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u SubmitStatus Descr ...
- Java学习之基本概念
1.java体系结构: j2se:是Java的标准版,用于标准的应用开. j2ee:是Java的企业版,用于企业级的应用服务,web服务开发. j2me:是Java的微型版,用户手机或嵌入式开发. p ...
- PostgreSQL源码解读 基础结构 node
一.node节点的定义 源代码路径postgresql-9.2.3/src/include/nodes/nodes.h 在查询解析SQL的查询部分,要用到大量的结构体,许多函数处理的逻辑类似,就是传入 ...
- mysql的binlog详解
什么是binlogbinlog日志用于记录所有更新了数据或者已经潜在更新了数据(例如,没有匹配任何行的一个DELETE)的所有语句.语句以“事件”的形式保存,它描述数据更改. binlog作用因为有了 ...
- Effective C++ 条款42
本节条款我们讨论一下class 关键字和typename关键字的不同以及对于模板函数(template function)的影响. 例如以下代码: template<class T> T ...
- Java程序员从笨鸟到菜鸟之(十四)Html基础积累总结(上)
本文来自:曹胜欢博客专栏.转载请注明出处:http://blog.csdn.net/csh624366188 注:由于本文内含有大量html标签,所以在排版上有些困难,所以排版有点难看,请大家见谅 ...
- ivy
ivy https://ant.apache.org/ivy/ Apache Ivy™ is a popular dependency manager focusing on flexibility ...
- zTree async 动态参数处理
async:{ enable: true,//开启异步机制 url: opts.url,//异步地址 otherParam: { 'plateNo': function(){ return $('# ...
- iOS中区分照片的来源
原理就是通过枚举出每个assets group,然后取得group property,group property是个整数,对应头文件中的一些枚举值.用这个可以判断照片是从哪来的(相机胶卷.照片流.相 ...
- umask文件屏蔽字的使用【学习笔记】
#include "apue.h" #include <fcntl.h> #define RWRWRW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP ...