본문 바로가기

BOJ

백준 3568 / iSharp



신박한 문제


문제에 제시된 조건대로 풀면되는데,


변수 이름은 거꾸로 뒤집어지면 안된다.


곧, [], &, *이 아닌 문자라면 따로 담아주어 처리해주어야 한다.


이때 reverse를 사용했다. (vector 등 자료구조에 사용되는 reverse지만 string에도 적용된다!)





코드


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
 
using namespace std;
 
vector<string>arr;
 
int main() {
    //freopen("Text.txt", "r", stdin);
    string bas;
 
    cin >> bas;
 
    bool end = true;
 
    while (end) {
        string tmp;
        cin >> tmp;
 
        arr.push_back(tmp);
 
 
        for (char c : tmp) {
            if (c == ';') {
                tmp.pop_back();
                end = false;
            }
        }
    }
 
    for (int i = 0; i < arr.size(); i++) {
        string tmp;
        tmp = bas;
        
        string name;
        arr[i].pop_back();
        if (arr[i][arr[i].size() - 1== ',') {
            arr[i].pop_back();
        }
 
        for (int j = arr[i].size()-1; j >= 0; j--) {
            if (arr[i][j] == '[') {
                tmp.push_back(']');
            }
            else if (arr[i][j] == ']') {
                tmp.push_back('[');
            }
            else if (arr[i][j] == '&' || arr[i][j] == '*') {
                tmp.push_back(arr[i][j]);
            }
            
            else {
                name.push_back(arr[i][j]);
            }
        }
 
        reverse(name.begin(), name.end());
        tmp.push_back(' ');
        tmp += name;
        tmp.push_back(';');
 
        cout << tmp << endl;        
    }
}
cs


'BOJ' 카테고리의 다른 글

백준 16197 / 두 동전  (0) 2019.02.24
백준 15683 / 감시  (0) 2019.02.23
백준 15686 / 치킨 배달  (0) 2019.02.22
백준 15685 / 드래곤 커브  (0) 2019.02.21
백준 2933 / 미네랄  (1) 2019.02.21