Problem 1414 - URL

Problem 1414 - URL
Time Limit: 1000MS Memory Limit: 65536KB Difficulty: 3
Total Submit: 990 Accepted: 329 Special Judge: No
Description
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.

Input
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.

Output
For each test case, display addresses as required, each address on a separated line.
Add a blank line after each ‘Display’ operation.

Sample Input
1
10
Visit http://acm.whu.edu.cn
Visit http://acm.pku.edu.cn
Visit http://acm.timus.ru
Visit http://acm.whu.edu.cn
Visit http://acm.whu.edu.cn
Visit http://acm.pku.edu.cn
Display http://acm
Visit baidu.com
Visit www.whu.edu.cn
Display b
Sample Output
http://acm.whu.edu.cn
http://acm.pku.edu.cn
http://acm.timus.ru

baidu.com

Hint
Source

#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
    string prompt,str;
    int n,m;
    string visit("Visit");
    //string display("Display");    typedef map<string ,int> Urls;
    typedef Urls::const_iterator UrlsIter;

    typedef multimap<int ,string , greater<int> > Urlrank;
    typedef Urlrank::const_iterator RankIter;

    Urls url;
    Urlrank urlrank;

    cin>>n;

    while( n-- ){
        cin>>m;

        url.clear();
        urlrank.clear();

        while( m--){
            cin >> prompt >> str;

            if ( visit.compare(prompt)==0){
                url[str]++;
            }else{
                for(UrlsIter iter = url.begin(); iter != url.end(); iter++ ){
                    string tmp(iter->first);
                    if ( tmp.find(str) == 0 ){
                        urlrank.insert( make_pair( iter->second,iter->first ) );
                    }
                }

                for( RankIter iter = urlrank.begin(); iter != urlrank.end(); iter++)
                    cout << iter->second <<endl;

                cout <<endl;
                urlrank.clear();
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值