본문 바로가기

알고리즘/SW EXPERT

4751. 다솔이의 다이아몬드 장식

4751. 다솔이의 다이아몬드 장식


각 라인마다 다섯글자를 반복하도록 하였다.


단 마지막 글자의 경우에는 배열의 한칸씩 당겨서 map 변수에 저장하도록 하였다.


그리고 출력할 때는 map 에 0값을 집어넣고 0이 나올때까지 출력하면서 모두가 출력되도록 하면 끝


<정답 코드>


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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<iostream>
#include<string>
using namespace std;
char map[5][1000];
void init()
{
    for (int i = 0; i < 5; i++)
        for (int j = 0; j < 1000; j++)
            map[i][j] = '\0';
}
int main()
{
    int tc;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        init();
        string str;
        int len,index = 0;
        cin >> str;
        len = str.size();
        for (int line = 0; line < 5; line++
        {
            int tmp = 0;
            for (int i = 0; i < len; i++) {
                for (int j = 0; j < 5; j++) {
                    if (line == 0 || line == 4
                    {
                        if (j % 5 == 0)
                        {
                            map[line][tmp++= '.';
                        }
                        else if (j % 5 == 1)
                        {
                            map[line][tmp++= '.';
                        }
                        else if (j % 5 == 2)
                        {
                            map[line][tmp++= '#';
                        }
                        else if (j % 5 == 3)
                        {
                            map[line][tmp++= '.';
                        }
                        else if (j % 5 == 4)
                        {
                            map[line][tmp] = '.';
                        }
                    }
                    else if (line == 1 || line == 3)
                    {
                        if (j % 5 == 0)
                        {
                            map[line][tmp++= '.';
                        }
                        else if (j % 5 == 1)
                        {
                            map[line][tmp++= '#';
                        }
                        else if (j % 5 == 2)
                        {
                            map[line][tmp++= '.';
                        }
                        else if (j % 5 == 3)
                        {
                            map[line][tmp++= '#';
                        }
                        else if (j % 5 == 4)
                        {
                            map[line][tmp] = '.';
                        }
                    }
                    else
                    {
                        if (j % 5 == 0)
                        {
                            map[line][tmp++= '#';
                        }
                        else if (j % 5 == 1)
                        {
                            map[line][tmp++= '.';
                        }
                        else if (j % 5 == 2)
                        {
                            map[line][tmp++= str[index++];
                        }
                        else if (j % 5 == 3)
                        {
                            map[line][tmp++= '.';
                        }
                        else if (j % 5 == 4)
                        {
                            map[line][tmp] = '#';
                        }
                    }
                }
            }
        }
 
 
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 1000; j++)
            {
                if (map[i][j] == '\0')
                    break;
 
                cout << map[i][j];
            }
            cout << endl;
        }
        
 
    }
 
    return 0;
}
cs


반응형

'알고리즘 > SW EXPERT' 카테고리의 다른 글

4740. 밍이의 블록게임  (0) 2018.07.30
4615. 재미있는 오셀로 게임  (0) 2018.07.19
3421. 수제 버거 장인  (0) 2018.04.10
4206. 연구소 탈출  (0) 2018.04.09
4193. 수영대회 결승전  (0) 2018.04.09