Parsing URL
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 2609 Accepted Submission(s): 1237
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
Recommend
lcy | We have carefully selected several similar problems for you: 4020 4012 4013 4014 4015
比赛的时候我看到这题是很开心的,我开的这题,心里预估的是5分钟AC,然后感人的场景出现了,我更新的ACM头文件里面有个头文件导致一直submit failed!!
然后就交给队友去修改(几乎要被队友打死呜呜呜,队友重新写了一遍然后就过了
但是我今天补题的时候发现我考虑的很不全面,这道题找结尾的结束标志条件有两个!还有一个‘:’,这个在题目中是有写明的,但是我只看了个sample就在那里很开心的写了,读题很不仔细,要反思!
【补AC的代码】
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#define go(i,a,b) for(int i=a;i<=b;i++)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int maxn = 1e3 + 5;
char str[maxn];
int main()
{
int n;
cin>>n;
go(j,0,n-1)
{
mem(str);
int start = 0,e;
scanf("%s",str);
int len = strlen(str);
go(i,0,len-1)
{
if(str[i] == '/' && str[i-1] == '/')
{
start = i;
break;
}
}
go(i,start+1,len-1)
{
if(str[i] == '/' || str[i] == ':')
{
e = i;
break;
}
}
printf("Case #%d: ",j+1);
go(i,start + 1,e-1) cout<<str[i];
cout<<endl;
}
return 0;
}