HDU 4018 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

输出字符串中的主要网址。

#include<map>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 100005;
int T;
char s[maxn];

int main()
{
    scanf("%d", &T);
    for (int k = 1; k <= T; k++)
    {
        scanf("%s", s);
        int i = 0;
        for (; s[i] != '/'; i++);
        printf("Case #%d: ",k);
        for (i += 2; s[i] != '/'&&s[i] != ':'; i++) printf("%c", s[i]);
        printf("\n");
    }
}


你可能感兴趣的:(HDU)