URL(字符串)

来源:互联网 发布:centos 7 1611下载 编辑:程序博客网 时间:2024/05/20 15:39

描述:

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.


样例输入:

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


样例输出:

http://acm.whu.edu.cn
http://acm.pku.edu.cn
http://acm.timus.ru

baidu.com



题目大意:

访问网址有两种访问第一种是visit访问需要打网址全名另一种是display访问不需要打网址全称它自动会匹配此前输入过的网址按频率高到低输出如果频率一样根据字典数从小到大输出。每一个display后面需要输出而且输出完后要接空行。



#include<stdio.h>#include<string.h>#include<string>#include<iostream>#include<algorithm>using namespace std;int e;struct asd{string str;int n;}gw[105];bool cmp(asd A,asd B){if(A.n==B.n)returnA.str<B.str;elsereturn A.n>B.n;}void check(string str3){sort(gw,gw+e,cmp);int flag=0;for(int i=0;i<e;i++)//此前出现过的话则将访问量加一{if(gw[i].str==str3){gw[i].n++;flag=1;break;}}if(flag==0)//如果没出现的话将这个网址新加进去 {gw[e].str=str3;gw[e++].n=1;}}void compare1(string str3){int len=str3.length();for(int i=0;i<e;i++){if(gw[i].str.substr(0,len)==str3)//比较记录下来的网址中前len个字符与str3字符串相同的网址 cout<<gw[i].str<<endl;}}int main(){int t,n;string str1;string str2;scanf("%d",&t);while(t--){e=0;scanf("%d",&n);for(int i=0;i<n;i++){cin>>str1;if(str1=="Visit")                          //判断访问网址的方式 {cin>>str2;check(str2);//检查输入的网址之前有没有出现 }else{sort(gw,gw+e,cmp);//这个sort不能忘,忘掉的话可能会少数据 (一开始忘写一直wa) cin>>str2;compare1(str2);printf("\n");}} }return 0;}



原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 c照一次被扣12分怎么办 教师资格证认定申请表填错了怎么办 外地车在北京违章没有牡丹卡怎么办 护士辞职了原单位不给延续怎么办 护士证注册的单位倒闭了怎么办 护士证注册的医院倒闭了怎么办 显示发货了但没物流信息怎么办 考科目三被别人举报了怎么办 科目一考了5没过怎么办 常州c1驾驶证满了12分怎么办 预约科目三成功后没交钱怎么办 预约成功后驾校不提交档案怎么办 c2刚满一年的驾照扣12分怎么办 怀孕6个月咳嗽很厉害怎么办 家门口有电线杆影响我建楼房怎么办 卡丢了不知道卡号怎么办 驾考网上预约用户被锁定了怎么办 人才中心拿出来的户口掉了怎么办 父母是南京集体户孩子没户口怎么办 二建挂靠中介单位不给证怎么办 小包工头遇到工人在工地摔伤怎么办 外地人买了城中村的房子改造怎么办 深圳社保怀孕了产检异地怎么办 成都公租房租满6年怎么办 二建审核资料如果照片丢失怎么办 身份证被冒用在外地办社保怎么办 蔷薇的嫩叶都被太阳晒死了怎么办 乐视手机进水了屏幕失灵怎么办 乐视手机进水了屏幕不显示怎么办 美团商家单量出现下滑怎么办 想开个小超市没经营过怎么办 华为7c手机wifi信号差怎么办 贞子从电视里爬出来怎么办 2个月的婴儿吓到怎么办 排卵日同房了没避孕怕怀孕怎么办 妻子因为我欺骗她要跟我离婚怎么办 老婆用苹果手机共享我的位置怎么办 孕妇餐后2小时血糖偏高怎么办 孕妇血糖餐后2小时数值高怎么办 股市退市的话股民的钱怎么办 美股股票退市了手里的股票怎么办