본문 바로가기
  • 소소한 개발자 이야기
Algorithm Study/SWEA

(SWEA) 5658. [모의 SW 역량테스트] 보물상자 비밀번호

by Siwan_Min 2020. 4. 6.
728x90

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRUN9KfZ8DFAUo

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

문제는 링크를 통해 확인해 주시기 바랍니다. 

 

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
char ch[35];
char cv1[8]; // 0~n/4 
char cv2[8]; // n/4 ~ n/4*2;
char cv3[8]; // n/4*2 ~n/4*3
char cv4[8]; // n/4*2 ~ n
 
int result[40= { 0, };
int tc, n, k;
 
int main() {
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> tc;
 
    for (int t = 1; t <= tc; t++) {
 
        cin >> n >> k;
        cin >> ch;
 
        // for(int i = 0; i<n; i++){
        //   cout<<ch[i];
        // }
 
        // cout<<endl;
        int index = 0;
        for (int r = 0; r < n / 4; r++) {
            int temp = ch[n - 1];
 
            for (int i = n - 1; i > 0; i--) {
                ch[i] = ch[i - 1];
            }
            ch[0= temp;
            //cout<<ch<<endl;
 
            memset(cv1, NULLsizeof(cv1));
            for (int i = 0; i < n / 4; i++) {
                cv1[i] = ch[i];
                //cout<<cv1[i];
            }//cout<<endl;
            //cout<<cv1<<endl;
 
            memset(cv2, NULLsizeof(cv2));
            for (int i = n / 4; i < (n / 4* 2; i++) {
                cv2[i - n / 4= ch[i];
                //cout<<cv2[i-n/4];
            }//cout<<endl;
           // cout<<cv2<<endl;
 
            memset(cv3, NULLsizeof(cv3));
            for (int i = (n / 4* 2; i < (n / 4* 3; i++) {
                cv3[i - (n / 4* 2= ch[i];
                // cout<<cv3[i-(n/4)*2];
            }//cout<<endl;
           // cout<<cv3<<endl;
 
            memset(cv4, NULLsizeof(cv4));
            for (int i = (n / 4* 3; i < n; i++) {
                cv4[i - (n / 4* 3= ch[i];
                //cout<<cv4[i-(n/4)*3];
            }//cout<<endl;
            //cout<<cv4<<endl;
            result[index] = (int)strtol(cv1, NULL16); index++;
            result[index] = (int)strtol(cv2, NULL16); index++;
            result[index] = (int)strtol(cv3, NULL16); index++;
            result[index] = (int)strtol(cv4, NULL16); index++;
 
 
            // cout<<cv1<<cv2<<cv3<<cv4<<endl;
            // cout<<cv1<<endl;
            // cout<<cv2<<endl;
            // cout<<cv3<<endl;
            // cout<<cv4<<endl;
 
          // //10진수로 변환
        //   int nDec = (int)strtol(cv1, NULL, 16);
 
        //   //10진수 출력
        //   cout << nDec << endl;
 
        }
        sort(result, result + 30, greater<int>());
        int descResult[100= { 0, };
        int inx = 0;
        for (int i = 0; i < n; i++) {
            if (result[i] != result[i + 1]) {
                descResult[inx] = result[i];
                inx++;
            }
        }
 
        // for(int i = 0; i<n; i++){
        //   cout<<descResult[i]<<endl;
        // }
        cout <<"#"<<t<<" "<< descResult[k - 1<< endl;
        memset(descResult, 0sizeof(descResult));
        memset(result, 0sizeof(result));
        memset(ch, NULLsizeof(ch));
 
    }
 
    return 0;
}
 
/*
1
12 10
1B3B3B81F75E
 
2
12 10
1B3B3B81F75E
16 2
F53586D76286B2D8
*/
 
/*
int main(){
char ch[100] = "FF";
 
    //10진수로 변환
    int nDec = (int)strtol(ch, NULL, 16);
 
    //10진수 출력
    cout << nDec << endl;
 
    //대문자 출력
 
    //16진수 출력
    cout << hex << nDec <<endl;
}
*/
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

사각형의 각 변을 구간별로 나누어 한칸씩 회전시킨 다음 값을 10진수로 변환하여 출력 하도록 했습니다. 

구간을 네가지로 나누고 값을 이동할줄만 안다면 어려운 문제는 아닌거 같습니다. 

728x90

댓글