WOJ1414-URL
来源:互联网 发布:王朔人品知乎 编辑:程序博客网 时间:2024/06/16 19:22
WHU ACM Team is working on a brand new web browser named "Whu-Super-Browser". You're in response for a
powerful feature: recording the previous addresses. Moreover, when a string is inputted, the browser will display all the
addresses start with it. The addresses shall be sorted by visited times, in descending order. This feature is very useful to
users.
Can you complete it?
There're two kinds of operations:
Visit [url_str] : visit a website with the URL: [url_str].
Display [str] : display all addresses start with [str] and sort them by visited times, in descending order. If two addresses
have the same visited times, then sort them in the lexicographical order.
输入格式
The input consists of multiple test cases. The first line of input contains an integer T, which is the number of test cases.
Each test case is on several lines.
The first line of each test case consists of an integer N.
Each of the following N lines consists of an operation, Visit or Display.
[Technical Specification] T is an integer, and T <= 10.
N is an integer, and 1 <= N <=100.
There's NO blank line between test cases.
[url_str] and [str] only contains lower case letters 'a' - 'z', '.', '/', ':'. The length of [url_str] and [str] is greater than 0 and won't exceed 100.
输出格式
For each test case, display addresses as required, each address on a separated line.
Add a blank line after each 'Display' operation.
样例输入
110Visit http://acm.whu.edu.cnVisit http://acm.pku.edu.cnVisit http://acm.timus.ruVisit http://acm.whu.edu.cnVisit http://acm.whu.edu.cnVisit http://acm.pku.edu.cnDisplay http://acmVisit baidu.comVisit www.whu.edu.cnDisplay b
样例输出
http://acm.whu.edu.cnhttp://acm.pku.edu.cnhttp://acm.timus.rubaidu.com
#include<iostream>#include<string>#include<map>#include<vector>#include<algorithm>using namespace std;struct comp {string a;int b;} val;bool inorder(comp a,comp b) {if(a.b!=b.b) return a.b>b.b;return a.a<b.a;}int main() {int t,n;cin>>t;while(t--) {map<string,int> a;map<string,int>::iterator it;string c,d;int i;cin>>n;while(n--) {cin>>c>>d;vector<comp> e;if(c=="Visit") ++a[d];if(c=="Display") {for(it=a.begin(); it!=a.end(); it++) {if((*it).first.find(d)==0) {val.a=(*it).first,val.b=(*it).second;e.push_back(val);}}sort(e.begin(),e.end(),inorder);for(i=0; i<e.size(); i++) {cout<<e[i].a<<endl;}cout<<endl;}}}return 0;}
- WOJ1414-URL
- url
- URL
- URL
- url
- url
- URL
- url
- URL
- url
- url
- url
- URL
- Url
- url
- URL
- URL
- url
- 二叉树的遍历
- 网易2018校招编程题
- 70. Climbing Stairs
- 【数据结构】B树的特性
- 练习3: 求1+2!+3!+...+20!的和
- WOJ1414-URL
- 行内元素如何设置宽高
- 局域网内客户端无法使用机器名连接SQLServer服务器
- Atitit 理财之道---支出大骗局分析与防范
- ThinkPHP3.2 使用快递鸟-物流跟踪API
- Android四大核心组件之Service|AIDL使用详解
- 面试-框架-spring
- 一步步教你如何在ubuntu虚拟机中安装QEMU并模拟arm 开发环境(二)rootfs制作
- WOJ1420-可见点