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 | #include <stdio.h> #include <memory> #include <string.h> #include <queue> #include <algorithm> using namespace std; vector<int> num_list; queue<char> arr; int n, k; void find_number(queue<char> q); int hex_to_num(char c); int find_k_num(); int main() { int t; scanf("%d", &t); for (int test = 1; test <= t; test++) { num_list.clear(); scanf("%d %d", &n, &k); while (!arr.empty()) arr.pop(); char tmp[100]; scanf("%s", &tmp); for (int i = 0; i < n; i++) arr.push(tmp[i]); for (int i = 1; i <= n/4; i++) { find_number(arr); char f = arr.front(); arr.pop(); arr.push(f); } int rst = find_k_num(); printf("#%d %d\n", test, rst); } } void find_number(queue<char> q) { int len = n / 4; int tmp_num[5] = { 0 }; queue<char> tmp_q; tmp_q = q; for (int i = 1; i <= 4; i++) { for (int j = 0; j < len; j++) { int tmp_hex2num = hex_to_num(tmp_q.front()); tmp_q.pop(); tmp_num[i] += (tmp_hex2num * pow(16, len - 1 - j)); } } for (int i = 1; i <= 4; i++) num_list.push_back(tmp_num[i]); } int hex_to_num(char c) { if ('0' <= c && c <= '9') return (int)(c - '0'); else return ((int)(c - 'A') + 10); } int find_k_num() { int idx = 0; sort(num_list.begin(), num_list.end(), greater<int>()); int bef = -1; for (int i = 0; i < num_list.size(); i++) { if (bef != num_list[i]) { if (k - 1 == idx) { return num_list[i]; } idx++; } bef = num_list[i]; } } | cs |
문제 설명을 뭐같이 해서 해석하는데에 한참 걸렸다
문제 자체는 쉽다.
로직도 단순하고.
'삼성 코팅테스트 준비 > 모의 역량 테스트 문제' 카테고리의 다른 글
4012 요리사 (0) | 2020.03.03 |
---|---|
시간초과) 5653 줄기세포 배양 (0) | 2020.03.03 |
5656 벽돌깨기 (0) | 2020.03.02 |
5644 무선충전 (0) | 2020.03.02 |
4008 숫자만들기 (0) | 2020.01.16 |