It was an ordinary grim October morning. The sky was covered by heavy gray clouds. It was a little rainy. The rain drops fell on the windows with quiet bangs. Ilya was sitting at the computer and gloomy
looking out of the window at the bleak scenery. Suddenly, a note caught his attention from the lower right corner of the screen. It said: “You have 1 unread email message(s)”. The boy braced himself for a bit of useless spam and opened the letter. But it turned
out much more interesting...
Dear Sir, You have received this message from the “Rutnok BKS” HR department!
We have received your application for a software developer and we found your CV quite interesting. We would like to suggest a simple test task to evaluate your professional skills. Your task is to implement
the register system for a forum. It must support three types of operations:
- “register username password”: to register a new user with name “username” and password “password”. If such user already exists in the database, the system should output the error message “fail: user already exists”. Otherwise, it should output message “success:
new user added”.
- “login username password”: to log into the system as user “username” with password “password”. If such user does not exist, the system should output “fail: no such user”. Otherwise, if the user enters an incorrect password, the system should output “fail:
incorrect password”. Otherwise, if the user is already logged in the system at that moment, it should output “fail: already logged in”. Otherwise, it should output “success: user logged in”.
- “logout username”: to log out of the system as user “username”. If such user does not exist, the system should output “fail: no such user”. Otherwise, if the user isn’t in the system at that moment, it should output “fail: already logged out”. Otherwise,
it should output “success: user logged out”.
Use this letter as a formal description of the algorithm and follow the described format of system messages. Good luck!
Ilya stopped doing anything else and started solving the test task. You can try to solve it as well!
Input
The first line contains an integernthat is the number of operations (1 ≤n≤ 100). Each of the nextnlines contains a single query in the format given above. We can assume
that “username” and “password” are non-empty strings with length of up to 30 characters. All characters in these strings have codes from 33 to 126.
Output
For each operation, print the message on a single line in the format given above. Be sure to put spaces and punctuation marks in the right places in the messages.
Sample
input
output
6
register vasya 12345
login vasya 1234
login vasya 12345
login anakin C-3PO
logout vasya
logout vasya
|
success: new user added
fail: incorrect password
success: user logged in
fail: no such user
success: user logged out
fail: already logged out
|
实现一个登陆系统。
思路:
1 使用map,在map中的就是已经注册的了
2 使用数据结构保存用户名,是否登陆和密码
3 使用if else判断处理第一个字符串-命令
类似很多人都写的什么图书馆管理系统,什么信息系统之类的登陆控制管理,都是很简单的东西,一步一步写就不会错了,完成速度相当于打字速度。
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
using namespace std;
namespace
{
struct States
{
bool logined;
string name;
string pw;
States(string n="", string p="", bool l = false):
name(n), pw(p), logined(l){}
};
}
void TestTask2002()
{
int opTimes = 0;
cin>>opTimes;
unordered_map<string, States> umSS;
string command, name, pw;
while (opTimes--)
{
cin>>command>>name;
if ("register" == command)
{
cin>>pw;//logout不用pw的
if (umSS.count(name)) cout<<"fail: user already exists\n";
else
{
States st(name, pw);
umSS[name] = st;
cout<<"success: new user added\n";
}
}
else if ("login" == command)
{
cin>>pw;
if (!umSS.count(name)) cout<<"fail: no such user\n";
else if (pw != umSS[name].pw) cout<<"fail: incorrect password\n";
else if (umSS[name].logined) cout<<"fail: already logged in\n";
else
{
cout<<"success: user logged in\n";
umSS[name].logined = true;
}
}
else if ("logout" == command)
{
if (!umSS.count(name)) cout<<"fail: no such user\n";
else if (!(umSS[name].logined)) cout<<"fail: already logged out\n";
else
{
cout<<"success: user logged out\n";
umSS[name].logined = false;
}
}
}
}
分享到:
相关推荐
acm.timus.ru最全代码
Timus ... Problems code. (Mainly Java implementation) Chinese 刷题代码,主要是java实现,可能会有其他语言代码 代码来自LeetCode / NowCoder / timus 等 site url LeetCode NowCoder Timus LeetCode-cn
acm.timus.ru解决方案 这些是我对ACM.TIMUS.RU问题的解决方案
In the present world you frequently meet a lot of call numbers and they are going to be longer and longer. You need to remember such a kind of numbers. One method to do it in an easy way is to assign ...
timus.ru_solutions 使用的语言:Python 使用的Python版本:3.9 我可以用Python语言解决的一些问题在“ python”目录中。 有些解决方案可以在Java中运行,但确切的解决方案/算法在Python中不起作用! 不知道为什么我...
资源分类:Python库 所属语言:Python 资源全名:timus-sender-0.1.1.post1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
acm.timus.ru 1709 problem
timus.ru_solutions_python 使用的python:3.9 我可以用Python语言解决的一些问题在python目录中。 有些解决方案可以在Java中运行,但确切的解决方案/算法在Python中不起作用! 我不知道为什么
Timus上习题解答与代码参考,这一部分对应于Timus上的Beginner部分的习题
timus:Timus在线法官问题
将图表添加到Timus Online Judge配置文件 该扩展程序将已解决问题的数量图表添加到Timus Online Judge的个人资料和比较器中。 功能:*概要文件和比较中已解决问题计数的图表*向图表中添加更多用户,删除它们,自定义...
timus OJ 1197 lonesome kinght
Timus图表 将图表添加到Timus Online Judge个人资料中 特征 概要文件中和比较期间已解决问题的计数图表 向图表添加更多用户,删除它们,自定义图例颜色 缓存配置文件数据 隐藏图表 (可选)突出显示最近两个月内接受...
https://acm.timus.ru/problem.aspx?space=1&num=1119 题目答案
蒂莫斯 该文件夹包含用Python编写的文件(主要是Python2.7,有些是Python3.4)我通过这些文件在timus上通过了相应的测试。
Timus Online Judge 是俄罗斯最大的带有自动评判系统的编程问题档案。 问题主要是从在乌拉尔联邦大学、乌拉尔锦标赛、乌拉尔 ACM ICPC 次区域比赛和彼得罗扎沃茨克训练营举办的比赛中收集的。 这个存储库将是我在 ...
语言:English将图表添加到Timus Online Judge个人资料中该扩展程序将已解决问题的数量图表添加到Timus Online Judge的个人资料和比较器中。功能:*概要文件和比较中已解决问题计数的图表*向图表中添加更多用户,删除...
http://acm.timus.ru 俄罗斯乌拉尔大学在线题库 SGU http://acm.sgu.ru/ 俄罗斯圣萨拉托夫州大学在线题库 ELJ http://acm.mipt.ru/judge/bin/problems.pl?lang=en file:///M|/acm/ACM大量习题题库及建议培养计划.txt...
这是一份关于ACM在线评测系统(Online Judge,简称OJ)的推荐题库列表。ACM是国际大学生程序设计竞赛的简称,这些OJ网站收集了大量经典算法、数据结构的题目,可以用于训练和练习。文中列出了一些知名的国内外OJ网站,...
http://acm.timus.ru/problem.aspx?space=1&num=1362 一道树形动态规划的题目解答,ural1362