/
4606.cpp
48 lines (38 loc) · 886 Bytes
/
4606.cpp
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
46
47
48
/**
* 4606. The Seven Percent Solution
*
* 작성자: xCrypt0r
* 언어: C++14
* 사용 메모리: 1,988 KB
* 소요 시간: 0 ms
* 해결 날짜: 2020년 9월 9일
*/
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
const int size = 7;
char from[size] = { ' ', '!', '$', '%', '(', ')', '*' };
string to[size] = { "%20", "%21", "%24", "%25", "%28", "%29", "%2a" };
while (true)
{
string s, res = "";
getline(cin, s);
if (s == "#")
{
break;
}
for (auto& c : s)
{
auto last = from + size;
auto it = find(from, last, c);
int i = distance(from, it);
res += (it == last ? string(1, c) : to[i]);
}
cout << res << "\n";
}
}