본문 바로가기

성우리뷰

sw 문제 모의 역량테스트) 보물상자 비밀번호

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;
 
int main(void)
{
    int test_case;
    int T;
 
    //  setbuf(stdout, NULL);
 
    scanf("%d", &T);
    /*
    여러 개의 테스트 케이스를 처리하기 위한 부분입니다.
    */
    for (test_case = 1; test_case <= T; ++test_case)
    {
        int n, m;
        cin >> n >> m;
        int length = n / 4;
 
        //대입
        char* arr = new char[n];
 
        char charstr[28];
        scanf("%s", charstr);
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < length; j++) {
                arr[i*length + j] = charstr[i*length + j];
            }
        }
 
        string str;
        vector<string> vec;
        for (int k = 0; k < length; k++) {
            for (int i = 0; i < 4; i++) {
                str = "";
                for (int j = 0; j < length; j++) {
                    str.push_back(arr[i*length + j]);
                }
        //      cout << str << "\n";
                vec.push_back(str);
            }
        //  printf("//////////\n");
            char tmp = arr[n-1];
            for (int i = n - 1; i > 0; i--) {
                arr[i] = arr[i - 1];
        //      printf("%c ", *(arr+7));
            }
 
            arr[0] = tmp;
        }
         
        sort(vec.begin(), vec.end(), greater<string>());
        vec.erase(unique(vec.begin(), vec.end()), vec.end());
 
    //  for (auto a : vec) {
    //      cout << a << " ";
    //  }
    //  cout << "\n";
    //  printf("answer string ");
    //  cout << vec[m - 1] << "\n";
         
        int ans= 0;
        for (int i = 0; i < vec[m - 1].size(); i++) {
            if (vec[m - 1][i] >= 'A' && vec[m - 1][i] <= 'F') {
                ans = ans * 16 + vec[m - 1][i] - 'A' + 10;
            }
            else {
                ans = ans * 16 + vec[m - 1][i] - '0';
            }
        }
        printf("#%d %d\n", test_case, ans);
    }
 
    return 0;
}

'성우리뷰' 카테고리의 다른 글

매출하락 최소화  (2) 2021.05.26
임시 공부용  (1) 2021.05.24
2021 카카오)순위 검색  (1) 2021.05.05
2021) 카카오 - 메뉴 리뉴얼  (2) 2021.05.02
.  (0) 2021.01.05