URAL 2002. Test Task (阅读理解)
来源:互联网 发布:matlab提取矩阵一部分 编辑:程序博客网 时间:2024/05/21 10:19
2002. Test Task
Time limit: 0.5 second
Memory limit: 64 MB
Memory limit: 64 MB
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 integer n that is the number of operations (1 ≤n ≤ 100). Each of the next n lines 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
6register vasya 12345login vasya 1234login vasya 12345login anakin C-3POlogout vasyalogout vasya
success: new user addedfail: incorrect passwordsuccess: user logged infail: no such usersuccess: user logged outfail: already logged outProblem Author: Kirill Borozdin
Problem Source: Ural Regional School Programming Contest 2013
解析:阅读理解,按照敲就完了。
AC代码:
#include <bits/stdc++.h>using namespace std;map<string, bool> m;map<string, string> p;int main(){ #ifdef sxk freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // sxk int n; string s, ss, pass; while(~scanf("%d", &n)){ m.clear(); p.clear(); for(int i=0; i<n; i++){ cin>>s; if(s == "register"){ cin>>ss>>pass; if(m.count(ss)) puts("fail: user already exists"); else{ puts("success: new user added"); m[ss] = false; p[ss] = pass; } } else if(s == "login"){ cin>>ss>>pass; if(m.count(ss) == 0) puts("fail: no such user"); else if(p[ss] != pass) puts("fail: incorrect password"); else if(m[ss]) puts("fail: already logged in"); else{ puts("success: user logged in"); m[ss] = true; } } else{ cin>>ss; if(m.count(ss) == 0) puts("fail: no such user"); else if(m[ss] == false) puts("fail: already logged out"); else{ puts("success: user logged out"); m[ss] = false; } } } } return 0;}
0 0
- URAL 2002. Test Task (阅读理解)
- URAL 2002. Test Task(登陆模拟 map )
- ural 2002. Test Task 简单模拟 stl map的使用
- URAL 1893. A380 (阅读理解 + 模拟)
- URAL 1083. Factorials!!! (阅读理解)
- URAL 1910 Titan Ruins: Hidden Entrance (阅读理解)
- URAL 1313 Some Words about Sport (阅读理解)
- timus 2002. Test Task
- Ural 1912 - Passing through Walls 阅读理解+BFS+高效Hash
- URAL 1873 GOV Chronicles = =这题是阅读理解?
- Timus 2002. Test Task 一个登陆系统
- 理解Task
- configuring gradle test task
- UVA494(阅读理解)
- timus 1346. Intervals of Monotonicity URAL 解题报告 DP 小水题,阅读理解
- URAL 1015. Test the Difference!
- ural 1015 Test the Difference!
- URAL 1873 大阅读题
- lua学习笔记之五(Lua中的数学库)
- 计算两个GPS坐标的距离 方法一 - C#语言
- c/c++线程--3线程池
- 【点滴】LINUX之find命令
- Halcon10 与 VC++交互,通过picture control显示图像
- URAL 2002. Test Task (阅读理解)
- 【python学习资料】各种python 函数参数定义和解析 --转载自byte_way
- Android 手机信号 dBm, asu
- Eclipse操作小技巧 , 快捷键
- Elliptic Curve Cryptography: a gentle introduction
- UIKit坐标系
- hdu 5233 Gunner II 【set+map】
- 150Evaluate Reverse Polish Notation
- Android判断用户2G/3G/4G移动数据网络