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;}
- URL(字符串)
- 有关字符串(正则表达式,URL字符串)
- Flex获取URL字符串
- URL字符串加密
- URL字符串操作
- url请求转义字符串
- 解密URL字符串
- url转成字符串
- 截取URL字符串
- js拼接URL字符串
- url 字符串截取
- url模块转换完整URL字符串
- URL重写(ASP.NET伪静态),字符串替换
- 查询url包含的字符串参数(js高程笔记)
- 对包含数据的url(字符串)的处理
- parse_str()—将url参数字符串转成数组
- URL字符串解析(UrlDecode vc)
- URL字符串解析(UrlDecode vc)
- Android 获取APK编译时间
- HDU 5832A water problem 简单模拟
- listagg函数将查询列转为行
- 类文件结构
- POJ-2528Mayor's posters(离散+线段树区间覆盖)
- URL(字符串)
- [BZOJ3395]回文串
- leetcode--84. Largest Rectangle in Histogram
- 安装samba
- MATLAB中文件的读写和数据的导入导出【转】
- 十二章 汇总数据
- 学奥数对孩子究竟有哪些好处?
- 小于等于n的素数的个数(埃式筛选法和欧拉筛选)
- Java中MD5计算摘要