HDU 4081-Parsing URL(水)

简介:

Parsing URL

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1575    Accepted Submission(s): 796


Problem Description
In computing, a Uniform Resource Locator or Universal Resource Locator (URL) is a character string that specifies where a known resource is available on the Internet and the mechanism for retrieving it.
The syntax of a typical URL is:
scheme://domain:port/path?query_string#fragment_id
In this problem, the scheme, domain is required by all URL and other components are optional. That is, for example, the following are all correct urls:
http://dict.bing.com.cn/#%E5%B0%8F%E6%95%B0%E7%82%B9
http://www.mariowiki.com/Mushroom
https://mail.google.com/mail/?shva=1#inbox
http://en.wikipedia.org/wiki/Bowser_(character)
ftp://fs.fudan.edu.cn/
telnet://bbs.fudan.edu.cn/
http://mail.bashu.cn:8080/BsOnline/
Your task is to find the domain for all given URLs.
 

Input
There are multiple test cases in this problem. The first line of input contains a single integer denoting the number of test cases.
For each of test case, there is only one line contains a valid URL.
 

Output
For each test case, you should output the domain of the given URL.
 

Sample Input
 
 
3 http://dict.bing.com.cn/#%E5%B0%8F%E6%95%B0%E7%82%B9 http://www.mariowiki.com/Mushroom https://mail.google.com/mail/?shva=1#inbox
 

Sample Output
 
 
Case #1: dict.bing.com.cn Case #2: www.mariowiki.com Case #3: mail.google.com
训练一下高速找到水题并切掉的能力。。毕竟现场赛仅仅能做水题了。

。7分钟1A

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
#define LL long long
char s[10010],ans[10010];
int main()
{
	//ios::sync_with_stdio(false);
	int t,p,cas=1;
	scanf("%d",&t);
	getchar();
	while(t--)
	{
		gets(s);
		int len=strlen(s);
		for(int i=0;i<len;i++)
		{
			if(s[i]=='/'&&s[i-1]=='/')
			{
				int j=i+1;p=0;
				while(s[j]!='/'&&s[j]!=':')
					ans[p++]=s[j++];
				break;
			}
		}
		printf("Case #%d: ",cas++);
		for(int i=0;i<p;i++)
			printf("%c",ans[i]);
		puts("");
	}
	return 0;
}


版权声明:本文博客原创文章。博客,未经同意,不得转载。





本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4651229.html,如需转载请自行联系原作者


相关文章
|
2月前
【latex】参考文献排版前移,在最前面引用\usepackage{url}
【latex】参考文献排版前移,在最前面引用\usepackage{url}
34 0
|
7月前
|
XML JSON 前端开发
SpringMVC运行项目出现The request sent by the client was syntactically incorrect.问题解决思路?
使用SpringMVC报HTTP Status 400 - The request sent by the client was syntactically incorrect.的错误怎么解决,你不妨看一下我的这个解决思路,再决定,往往你最忽略的地方就是你最容易报错的地方,所以我建议你看一看我的这个思路是否与你的问题一样
|
6月前
CTFShow--周末大挑战parse_url篇Writeup
CTFShow--周末大挑战parse_url篇Writeup
48 0
|
4月前
|
存储 XML JSON
@RequestBody、@RequestParam 、@PathVariable @RequestPart 傻傻分不清
@RequestBody、@RequestParam 、@PathVariable @RequestPart 傻傻分不清
55 0
|
9月前
|
Java Maven Spring
Failed to configure a DataSource: ‘url‘ attribute is not specified and no Reaso(附解决思路)
Failed to configure a DataSource: ‘url‘ attribute is not specified and no Reaso(附解决思路)
201 0
|
10月前
|
10月前
|
C++
【PAT甲级 - C++题解】1119 Pre- and Post-order Traversals
【PAT甲级 - C++题解】1119 Pre- and Post-order Traversals
46 0
|
数据采集 Python
Python爬虫:利用urlparse获取“干净”的url
Python爬虫:利用urlparse获取“干净”的url
111 0
|
Python
Python编程:urlsplit, urlparse简单区别
Python编程:urlsplit, urlparse简单区别