Advertisement
Guest User

mytona_3

a guest
Jan 26th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main() {
  5.     std::vector<std::string> url;
  6.     int n;
  7.     std::cout << "Введите количество строк: " << std::endl;
  8.     std::cin >> n;
  9.     for (int i = 0; i < n; i++) {
  10.         std::string buf;
  11.         std::cin >> buf;
  12.         url.push_back(buf);
  13.     }
  14.     for (int i = 0; i < n; i++) {
  15.         std::cout << "String № " << i << std::endl;
  16.         std::vector<std::string> buf;
  17.         int pos = url[i].find(':');
  18.         if (pos == -1) {
  19.             std::cout << "Protocol: " << "http" << std::endl;
  20.         } else {
  21.             std::cout << "Protocol: " << url[i].substr(0, pos) << std::endl;
  22.             url[i].erase(0, pos + 3);
  23.         }
  24.         pos = url[i].find(':');
  25.         if (pos != -1) {
  26.             std::cout << "Host: " << url[i].substr(0, pos) << std::endl;
  27.             url[i].erase(0, pos + 1);
  28.             std::cout << "Port: " << url[i].substr(0, 2) << std::endl;
  29.             url[i].erase(0, 4);
  30.         }
  31.         if (pos == -1) {
  32.             std::cout << "Port: " << 80 << std::endl;
  33.             pos = url[i].find('/');
  34.             std::cout << "Host: " << url[i].substr(0, pos) << std::endl;
  35.             if (pos != -1) {
  36.                 url[i].erase(0, pos + 1);
  37.                 if (url[i].size() != 0) {
  38.                     std::cout << "Page: " << url[i].substr(0, url[i].size()) << std::endl;
  39.                 }
  40.             }
  41.         }
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement