EOJ 2607/HDU 2698/WOJ 1414/The 4th Baidu Cup URL
来源:互联网 发布:知豆电动车能上高速吗 编辑:程序博客网 时间:2024/05/16 20:27
题目简介
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.
说明
简单的结构体排序题。用好map可以事半功倍。顺便放一下样例:
input:
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
output:
http://acm.whu.edu.cnhttp://acm.pku.edu.cnhttp://acm.timus.rubaidu.com
代码:
#include<bits/stdc++.h>using namespace std;struct url{string name; int cnt;};bool cmp(url a,url b){ if(a.cnt != b.cnt) return a.cnt > b.cnt; return a.name < b.name;}int main(){ int t, n; cin >> t; while(t--) { map<string, int> sites; string op, s; cin >> n; while(n--) { cin>> op >> s; vector<url> v; if(op == "Visit") ++sites[s]; if(op == "Display") { for(map<string, int>::iterator it = sites.begin(); it != sites.end(); ++it) if((*it).first.find(s) == 0) v.push_back({(*it).first, (*it).second}); sort(v.begin(), v.end(), cmp); for(int i = 0; i < v.size(); ++i) cout<< v[i].name << endl; cout << endl; } } } return 0;}
- EOJ 2607/HDU 2698/WOJ 1414/The 4th Baidu Cup URL
- hdu 5999 The Third Cup is Free
- HDU 5999 The Third Cup is Free
- hdu 2697 WOJ dp
- HDU 4018 Parsing URL 正则表达式 The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup
- [hdu] CUP
- hdu 5102 The K-th Distance
- 【HDU】5102 The K-th Distance bfs
- HDU 5102 The K-th Distance
- HDU - 5999 The Third Cup is Free 贪心
- HDU 5999—The Third Cup is Free
- WOJ
- woj
- EOJ 1095 Guess the Number
- EOJ 2521 Guarding the Farm
- HDU 3153 Pencils from the 19th Century(数学题)
- hdu 5102 The K-th Distance(特殊的搜索技巧)
- HDU-5102-The K-th Distance【思维】【好题】
- 读后感——《软件工程》——软件的本质及软件工程
- ssm项目无法找到资源404错误
- jetty maven plugs 中的配置:
- 机房收费系统之初进行
- Android MVC MVP MVVM
- EOJ 2607/HDU 2698/WOJ 1414/The 4th Baidu Cup URL
- 关于easyNVR的录像功能
- qwb的骚扰
- 鸡兔同笼
- 编译原理
- Autodesk Showcase 2017破解教程(附加下载地址/序列号)
- SDUT-3399-->数据结构实验之排序二:交换排序
- 176. Spring Boot WebSocket:汇总篇
- nodejs学习笔记3