hdu 4018 Parsing URL

                                               Parsing URL

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


Source
The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup
嗯,好吧,其实这个题没什么好讲的。。。只是刚开始只看样例,没注意到题目中的介绍,结束除了以‘/’以外,还有':'....

#include<iostream>
using namespace std;
int main()
{
	int n,i;
	while(cin>>n)
	{
		for(i=1;i<=n;i++)
		{
			char a[100],b[100];
			cin>>a;
			int j,k=0;
			//输出'//'与'/'或':'之间的字符串
			for(j=0;j<strlen(a);j++)
			{
				if(a[j]=='/' && a[j+1]=='/')
					break;
			}
			for(j+=2;a[j]!='/'&&a[j]!=':';j++)
			{
				b[k++]=a[j];
			}
			cout<<"Case #"<<i<<": ";
			for(j=0;j<k;j++)
				cout<<b[j];
			cout<<endl;
		}
	}
	return 0;
}


 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值