Posted on 2008-05-08 15:07
superman 阅读(298)
评论(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