https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV13zo1KAAACFAYh&categoryId=AV13zo1KAAACFAYh&categoryType=CODE
정렬, look-up table
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 | #include <stdio.h> typedef struct st_ { int num; int val; }ST; #define SWAP(x,y) {ST temp; temp=x; x=y; y=temp;} int T, tc; ST a[100+10]; void init(void) { int i; for (i = 0; i <= 100; i++) { a[i].val = 0; } } void input(void) { int i; int score; scanf("%d", &tc); for (i = 1; i <= 1000; i++) { scanf("%d", &score); a[score].num = score; a[score].val++; } } void sort(void) { int i, j; for (i = 1; i <= 100; i++) { for (j = 0; j < i; j++) { if (a[j].val < a[i].val) { SWAP(a[i], a[j]); } else if (a[j].val == a[i].val && a[j].num < a[i].num) { SWAP(a[i], a[j]); } } } } void output(void) { printf("#%d %d\n", tc, a[0].num); } int main(void) { scanf("%d", &T); for (tc = 1; tc <= T; tc++) { init(); input(); sort(); output(); } return 0; } | cs |
'알고리즘 > SW Expert Academy' 카테고리의 다른 글
1244 최대 상금 (0) | 2018.09.20 |
---|---|
1210 Ladder1 (0) | 2018.09.20 |
1206 View (0) | 2018.09.18 |
1251 하나로 (0) | 2018.09.18 |
1868 파핑파핑 지뢰찾기 (0) | 2018.09.18 |