• Source
    1. #include <iostream>
    2. #include <algorithm>
    3. #include <vector>
    4. using namespace std;
    5.  
    6. struct data
    7. {
    8. long long GT;
    9. int sl;
    10. int bd;
    11. };
    12.  
    13. int cmp (data a, data b)
    14. {
    15. if (a.sl<b.sl) return 0;
    16. else if (a.sl==b.sl)
    17. {
    18. if (a.bd>b.bd) return 0;
    19. }
    20. return 1;
    21. }
    22.  
    23. int main ()
    24. {
    25. int N;
    26. long long C;
    27. cin>>N>>C;
    28. struct vector <data> V;
    29. struct data tg;
    30. for (int i=1; i<=N; i++)
    31. {
    32. cin>>tg.GT;
    33. int kt=0;
    34. for (int j=0; j<V.size(); j++)
    35. {
    36. if (V[j].GT==tg.GT)
    37. {
    38. kt=1;
    39. V[j].sl++;
    40. break;
    41. }
    42. }
    43. if (kt==0)
    44. {
    45. tg.sl=1;
    46. tg.bd=i;
    47. V.push_back(tg);
    48. }
    49. }
    50. sort (V.begin(), V.end(), cmp);
    51. for (int i=0; i<V.size(); i++)
    52. {
    53. for (int j=0; j<V[i].sl; j++)
    54. {
    55. cout<<V[i].GT<<" ";
    56. }
    57. }
    58. return 0;
    59. }