문자열 파싱 + 구현문제라고 해야하나


출력형식에 유의해야 한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
#pragma warning(disable:4996)
 
string d = "<default>";
 
int main() {
    int t;
    scanf("%d\n"&t);
    for (int tc = 1; tc <= t; tc++) {
        string s;
        cin >> s;
        int len = s.length(), st;
        string protocol = "", host = "", port = d, path = d;
        
        if (s[0== 'f') protocol = "ftp", st = 6;
        else if (s[0== 'h') protocol = "http", st = 7;
        else protocol = "gopher", st = 9;
 
        for (; st < len && s[st] != ':' && s[st] != '/'; st++
            host += s[st];
 
        if (st < len && s[st] == ':') {
            port = "";
            st++;
            while (st < len && s[st] != '/') port += s[st], st++;
        }
 
        if (st < len) {
            st++;
            path = "";
            while (st < len) path += s[st], st++;
        }
        cout << "URL #" << tc << '\n';
        cout << "Protocol = " << protocol << '\n';
        cout << "Host     = " << host << '\n';
        cout << "Port     = " << port << '\n';
        cout << "Path     = " << path << '\n';
        cout << '\n';
    }
    return 0;
}
cs


'BOJ' 카테고리의 다른 글

1922 네트워크 연결  (0) 2018.04.04
10840 구간성분  (0) 2018.04.04
2257 화학식량  (0) 2018.04.04
14617 제 3회 IUPC  (0) 2018.03.09
10573 증가하는 수  (0) 2018.02.18

+ Recent posts