`
bcyy
  • 浏览: 1951513 次
文章分类
社区版块
存档分类
最新评论

Timus 2002. Test Task 一个登陆系统

 
阅读更多

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:
  1. “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”.
  2. “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”.
  3. “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最全代码

    【acm.timus.ru最全代码】集合是一个包含大量算法和解决方案的资源库,专为参与ACM(国际大学生程序设计竞赛)的参赛者提供。这个压缩包可能包含了成千上万的源代码文件,涵盖了从基础算法到复杂数据结构的各种问题...

    leetcode中国-InterView_Problem:LeetCode/NowCoder/Timus...问题代码。(主要是Java实现)

    Timus ... Problems code. (Mainly Java implementation) Chinese 刷题代码,主要是java实现,可能会有其他语言代码 代码来自LeetCode / NowCoder / timus 等 site url LeetCode NowCoder Timus LeetCode-cn

    acm.timus.ru-solutions:这些是我对ACM.TIMUS.RU问题的解决方案

    在ACM竞赛编程领域,TIMUS(Time Limit Exceeded)是一个知名的在线判题系统,它提供了大量的算法题目供参赛者练习和挑战。本压缩包"acm.timus.ru-solutions"包含了作者对于TIMUS平台上问题的解答,主要使用Java语言...

    https://acm.timus.ru/print.aspx?space=1&num=1002 题目答案

    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

    timus.ru_solutions 使用的语言:Python 使用的Python版本:3.9 我可以用Python语言解决的一些问题在“ python”目录中。 有些解决方案可以在Java中运行,但确切的解决方案/算法在Python中不起作用! 不知道为什么我...

    timus-1709.rar_数据结构_Visual_C++_

    标题中的"timus-1709.rar_数据结构_Visual_C++_"指的是一个与ACM编程竞赛相关的题目,具体来说是TIMUS在线判题系统中的第1709号问题,这个问题需要使用数据结构和Visual C++编程语言来解决。在ACM(国际大学生程序...

    Timus_Beginner

    Timus Online Judge是一个专门用于编程竞赛和算法练习的在线系统,它提供了丰富的题目供用户进行编程挑战,以提升算法理解和编程技能。"Beginner"级别是入门阶段,适合刚刚接触算法或编程基础较薄弱的学习者。 在...

    Python库 | timus-sender-0.1.1.post1.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:timus-sender-0.1.1.post1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    timus.ru_solutions_python

    timus.ru_solutions_python 使用的python:3.9 我可以用Python语言解决的一些问题在python目录中。 有些解决方案可以在Java中运行,但确切的解决方案/算法在Python中不起作用! 我不知道为什么

    timus:Timus在线法官问题

    这个平台主要支持C++语言,因此我们重点讨论与C++相关的知识点。 1. **C++基础** C++是一种强大的、面向对象的编程语言,它继承了C语言的特性并引入了类、模板、异常处理等高级概念。在Timus平台上,你需要熟悉C++...

    timus:用Python完成的timus上的题目

    这意味着这个压缩包里的代码文件都是经过实践验证的,每个文件都对应着Timus上的一个具体题目,且已经通过了官方的自动测试系统。Python2.7是Python的一个老版本,虽然现在已经不再支持,但在很多旧项目和竞赛中仍然...

    Timus图表「Timus Charts」-crx插件

    将图表添加到Timus Online Judge配置文件 该扩展程序将已解决问题的数量图表添加到Timus Online Judge的个人资料和比较器中。 功能:*概要文件和比较中已解决问题计数的图表*向图表中添加更多用户,删除它们,自定义...

    timus OJ 1197

    在本题目中,我们探讨了一个有趣的国际象棋问题——如何计算在一个特殊定义的棋盘上,一个“孤独的骑士”能攻击到的格子数量。此题目属于算法竞赛中的基础题型之一,涉及数组、输入输出以及简单的逻辑处理等知识点。...

    timus-charts:将图表添加到Timus Online Judge个人资料中

    Timus图表 将图表添加到Timus Online Judge个人资料中 特征 概要文件中和比较期间已解决问题的计数图表 向图表添加更多用户,删除它们,自定义图例颜色 缓存配置文件数据 隐藏图表 (可选)突出显示最近两个月内接受...

    timus-online-judge:Timus Online Judge 是俄罗斯最大的带有自动评判系统的编程问题档案。 问题多来自于在乌拉尔联邦大学、乌拉尔锦标赛、乌拉尔ACM ICPC分区域比赛和彼得罗扎沃茨克训练营举办的比赛中收集的问题

    Timus Online Judge 是俄罗斯最大的带有自动评判系统的编程问题档案。 问题主要是从在乌拉尔联邦大学、乌拉尔锦标赛、乌拉尔 ACM ICPC 次区域比赛和彼得罗扎沃茨克训练营举办的比赛中收集的。 这个存储库将是我在 ...

    学习C语言的好网站和在线裁判系统 一些网站

    综上所述,以上介绍的网站和在线裁判系统不仅为学习C语言提供了丰富的资源,同时也为编程爱好者提供了一个展示和提升自我技能的良好平台。无论是初学者还是有一定基础的学习者,都能从中获益匪浅。

    ACM网站大全(OJ+代码+贴吧)

    - SPOJ是一个非常著名的国际在线评测系统,拥有大量经典算法问题。 以上列出的在线评测系统都是国内外知名的ACM编程竞赛平台,每个平台都有其特色和优势。对于学习算法、参加竞赛的学生和爱好者来说,这些资源是不...

    acm_ural_1099

    【描述】"Pascal acm_timus_ural_1099.pas" 指的是这个问题的一个具体实现,使用了Pascal编程语言。Pascal是一种结构化的、静态类型的编程语言,它在教学和算法竞赛中广泛使用,因其清晰的语法结构而受到青睐。`acm_...

    Timus Charts-crx插件

    语言:English将图表添加到Timus Online Judge个人资料中该扩展程序将已解决问题的数量图表添加到Timus Online Judge的个人资料和比较器中。功能:*概要文件和比较中已解决问题计数的图表*向图表中添加更多用户,删除...

    ACM必备书籍及相关网站地址

    - 另一个知名的在线评测平台,收录了大量的经典题目。 10. **ACM-ICPC官方网站**:[http://icpc.baylor.edu/icpc/](http://icpc.baylor.edu/icpc/) - 国际大学生程序设计竞赛的官方网站,提供了赛事信息和历届...

Global site tag (gtag.js) - Google Analytics