superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ZOJ 1243 - URLs

Posted on 2008-05-08 15:07 superman 阅读(281) 评论(0)  编辑 收藏 引用 所属分类: ZOJ
 1 /* Accepted 1243 C++ 00:00.00 848K */
 2 #include <string>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int n; string s;
10     
11     cin >> n;
12     for(int i = 1; i <= n; i++)
13     {
14         int p;
15         cin >> s;
16         
17         p = s.find("://");
18         
19         string protocol = s.substr(0, p);
20         string host = s.substr(p + 3, s.size());
21         string port;
22         string path;
23         
24         p = host.find('/');
25         if(p != string::npos)
26         {
27             path = host.substr(p + 1, host.size());
28             host = host.substr(0, p);
29         }
30         
31         p = host.find(':');
32         if(p != string::npos)
33         {
34             int k;
35             for(k = p + 1; isdigit(host[k]); k++)
36                 port += host[k];
37             host = host.substr(0, p);
38         }
39         
40         cout << "URL #" << i << endl
41              << "Protocol = " << protocol << endl
42              << "Host     = " << host     << endl
43              << "Port     = " << (port == "" ? "<default>" : port) << endl
44              << "Path     = " << (path == "" ? "<default>" : path) << endl << endl;
45     }
46     
47     return 0;
48 }
49 

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理