Try
[Programmers/C++] 최빈값 구하기 본문
출처
http://codingdojang.com/scode/612#answer-filter-area
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 | /* /* /* khsh5592@naver.com /* has3ong.tistory.com /* /* 2018 - 11 - 12 /* */ #include <stdio.h> #include <conio.h> #include <iostream> using namespace std; //int Check_Data[5] = {12, 17, 19, 17, 23}; //17 int Check_Data[5] = {26, 37, 26, 37, 91}; //26, 37 //int Check_Data[5] = {28, 30, 32, 34, 144}; // 없다. typedef struct Select { int count; int Data; bool answer; }; void Check_Array() { Select S[5]; int location = 0; int size = 0; int max = 0; for(int i = 0; i<5; i++) { S[i].count = 0; S[i].Data = 0; S[i].answer = false; } int count = sizeof(Check_Data) / sizeof(int); for(int i = 0; i< count; i++) { for(int j = 0; j<count; j++) { if(S[j].Data == Check_Data[i]) { S[j].Data = Check_Data[i]; S[j].count ++; S[j].answer = true; break; } else if ( j == count-1) { S[location].Data = Check_Data[i]; S[location].count ++; S[location].answer = true; location++; } } } int check = 0; for(int i = 0; i<count; i++) { if(max <= S[i].count) { max = S[i].count; check ++; } } if(check == count) { cout<< " 없다. "; return; } else { for(int i = 0; i<count; i++) { if(max == S[i].count) { cout << " [ " << S[i].Data << " ] "; } } } } void main() { Check_Array(); getch(); } | cs |
'Algorithm > Programmers' 카테고리의 다른 글
[Programmers/C++] 소수의 합 (0) | 2018.11.15 |
---|---|
[Programmers/C++] 카펫 (0) | 2018.11.12 |
[Programmers/C++] 타겟 넘버 (0) | 2018.11.12 |
[Programmers/C++] 피보나치 시저 암호 (0) | 2018.11.12 |
[Programmers/C++] Ugly Number 구하기 (0) | 2018.11.12 |
Comments