Parsing URL
Parsing URL
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 1693 Accepted Submission(s): 864
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.
For each of test case, there is only one line contains a valid URL.
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
Case #1: dict.bing.com.cn Case #2: www.mariowiki.com Case #3: mail.google.com
#include<iostream> #include<string> using namespace std; int main() { int T,start,end1,end2,i,count=1; string str; cin>>T; while(T--) { cin>>str; start=str.find("://"); end1=str.find('/',start+3); end2=str.find(':',start+3); printf("Case #%d: ",count++); if(end2!=-1 && end1!=-1) { if(end1<end2) { for(i=start+3;i<end1;i++) cout<<str[i]; cout<<endl; } if(end1>end2) { for(i=start+3;i<end2;i++) cout<<str[i]; cout<<endl; } } if(end1==-1) { for(i=start+3;i<end2;i++) cout<<str[i]; cout<<endl;} if(end2==-1) { for(i=start+3;i<end1;i++) cout<<str[i]; cout<<endl; } } return 0; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。