zoj 1243
来源:互联网 发布:matlab如何读取usb数据 编辑:程序博客网 时间:2024/04/29 08:27
//水#include <iostream> #include <string> using namespace std;int main(){ int cases; string str1, protocol, port, address, dictionary; cin >> cases; for (int t = 0; t != cases; ++t) { cin >> str1; protocol = address = ""; port = dictionary = "<default>"; int pos = str1.find("://"); protocol = str1.substr(0, pos); str1 = str1.substr(pos + 3); pos = str1.find(":"); int pos2 = str1.find("/"); if (pos > 0 && (pos2 > pos || pos2 == -1)) { address = str1.substr(0, pos); if (pos2 > 0) { port = str1.substr(pos + 1, pos2 - pos - 1); dictionary = str1.substr(pos2 + 1); } else port = str1.substr(pos + 1); } else { if (pos2 > 0) { dictionary = str1.substr(pos2 + 1); address = str1.substr(0, pos2); } else address = str1; } cout << "URL #" << t + 1 << endl; cout << "Protocol = " << protocol << endl; cout << "Host = " << address << endl; cout << "Port = " << port << endl; cout << "Path = " << dictionary << endl << endl; } return 0; }