백준
백준 6324 URLs
콩순이냉장고
2021. 9. 1. 22:40
문제 URL : https://www.acmicpc.net/problem/6324
6324번: URLs
For each URL in the input first print the number of the URL, as shown in the sample output. Then print four lines, stating the protocol, host, port and path specified by the URL. If the port and/or path are not given in the URL, print the string
www.acmicpc.net
문제 접근법 : 노가다적으로 풀수도있지만 시험에선 빠르게 푸는게 좋겠죠?
쉽게쉽게 풀자구여 정규표현식 패턴 한문장에 끝나는 문제입니다. 코드를 보시고 공부가 되셨으면좋겠네요
소스코드 :
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
|
//By 콩순이냉장고
#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> v;
void input() {
cin >> n;
v.resize(n);
for (int i = 0; i < n; i++)
cin >> v[i];
}
void solve() {
string p1 = R"((\w+)://([\w\.-]+):?(\d*)/?(\S+)*)";
vector<string> sv = { "Protocol = ","Host = ","Port = ","Path = " };
for (int i = 0; i < v.size(); i++) {
smatch match;
regex_search(v[i], match, regex(p1));
cout << "URL #" << i + 1 << "\n";
for (int j = 1; j <= 4; j++) {
cout << sv[j - 1] << (match[j].str().empty() ? "<default>" : match[j].str()) << "\n";
}
cout << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
input();
solve();
}
|
cs |

궁금한점 혹은 모르는점 논리적인 오류등 어떤질문이든 댓글은 언제나 환영입니다.
공감도 눌러주실꺼죠?