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 " ...
随机推荐
- jQuery Ajax Post Data Example
http://www.formget.com/jquery-post-data/ jQuery Ajax Post Data Example Fugo Of FormGet jQuery $.post ...
- Json实现异步请求(提交评论)
主要将代码粘贴,通过阅读代码理解当中的相关逻辑. html代码: <form id="form1" runat="server"> <p> ...
- SVN——库合并
从下午開始做库的合并.刚開始一直将路径弄错.后来纠结至死的时候,finally and finally,succeed~ 库合并是这样子的: 如今,我要把项目1这个库合并到部门1的项目1目录中,为了 ...
- 软件版本号(BETA、RC、ALPHA、Release、GA等)
Alpha: Alpha是内部测试版,一般不向外部发布,会有很多Bug.除非你也是测试人员,否则不建议使用.是希腊字母的第一位,表示最初级的版本,alpha 就是α,beta 就是β , ...
- java设计模式----真实世界的模式
设计模式的定义: 模式是在某情境下,针对某问题的某种解决方案 反模式: 告诉你如何采用一个不好的解决方案解决一个问题 要点: 1.让设计模式自然而然地出现在你的设计中,而不是为了使用而使用 2.设计模 ...
- ubuntu搭建samba服务器
一.为什么要用Samba? Samba的主要任务就是实现Linux系统和Windows系统之间的资源共享. 二.需要的软件? 我是在ubuntu上实现的,所以我只需在配置好ubuntu的更 ...
- React Native安装
1.安装 1.1 安装Node.js 下载安装即可 1.2 安装Homebrew 终端中执行: $ /usr/bin/ruby -e "$(curl -fsSL https://raw.gi ...
- 浅谈C#中常见的委托
一提到委托,浮现在我们脑海中的大概是听的最多的就是类似C++的函数指针吧,呵呵,至少我的第一个反应是这样的. 关于委托的定义和使用,已经有诸多的人讲解过,并且讲解细致入微,尤其是张子阳的那一篇.我就不 ...
- Hadoop 中的 (side data) 边数据
一.用途 边数据是作业所需的额外的只读数据,通常用来辅助主数据集: 二.方法 1.利用Configuration类来配置,利用setter()和getter()可方便的使用,方便存储一些基本的类型: ...
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...