4676 늘어지는 소리 만들기


check배열에 하이픈 위치 기록하여 중간중간 출력해주면 된다.


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
#include <iostream>
#include <string>
#include <memory.h>
using namespace std;
 
int t;
int check[20];
 
int main() {
    ios_base::sync_with_stdio(false);
 
    cin >> t;
 
    for (int tc = 1; tc <= t; tc++) {
        memset(check, 0sizeof(check)); //check배열 초기화
 
        string buf;
        int x, h, a = 0;
 
        cin >> buf >> h;
 
        //하이픈 위치 기록
        for (int i = 0; i < h; i++) {
            cin >> x;
            if (x >= buf.length()) {
                a++;
            }
            else {
                check[x]++;
            }
        }
 
        cout << "#" << tc << " ";
        //문자열 및 하이픈 출력
        for (int i = 0; i < buf.length(); i++) {
            for (int j = 0; j < check[i]; j++) {
                cout << "-";
            }
            cout << buf[i];
        }
        for (int i = 0; i < a; i++) {
            cout << "-";
        }
 
        cout << "\n";
    }
}
cs


'SWEA::문제풀이' 카테고리의 다른 글

균형점  (0) 2018.09.06
최대 상금  (0) 2018.09.06
2117 홈 방범 서비스  (0) 2018.04.14
2112 보호 필름  (3) 2018.04.13
4112 이상한 피라미드 탐험  (0) 2018.04.12

+ Recent posts