HDU

来源:互联网 发布:excel数据透视表题目 编辑:程序博客网 时间:2024/05/21 06:52

Parsing URL

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


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
3http://dict.bing.com.cn/#%E5%B0%8F%E6%95%B0%E7%82%B9http://www.mariowiki.com/Mushroomhttps://mail.google.com/mail/?shva=1#inbox
 

Sample Output
Case #1: dict.bing.com.cnCase #2: www.mariowiki.comCase #3: mail.google.com
 

Source
The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup 
 

就是求域名(在"//"之后":"或"/"之前的字符串)

#include<iostream>#include<stdio.h>#include<string.h>#include<string>using namespace std;int n;string s,ans;int main(){    while(scanf("%d",&n)!=EOF)    {        for(int cas = 1;cas<=n;cas++)        {            cin>>s;            ans = "";            for(int i=0;i<s.size();i++)            {                if(s[i]=='/'&&s[i+1]=='/')                {                    for(int j=i+2;j<s.size();j++)                    {                        if(s[j]=='/'||s[j]==':')                            break;                        ans += s[j];                    }                    break;                }            }            cout<<"Case #"<<cas<<": "<<ans<<endl;        }    }    return 0;}



原创粉丝点击