fork download
  1. #include<stdio.h>
  2. void merge(int arr[],int l,int m,int r)
  3. {
  4. int i, j, k;
  5. int n1 = m - l + 1;
  6. int n2 = r - m;
  7.  
  8. /* create temp arrays */
  9. int L[n1], R[n2];
  10.  
  11. /* Copy data to temp arrays L[] and R[] */
  12. for(i = 0; i < n1; i++)
  13. L[i] = arr[l + i];
  14. for(j = 0; j < n2; j++)
  15. R[j] = arr[m + 1+ j];
  16.  
  17. /* Merge the temp arrays back into arr[l..r]*/
  18. i = 0;
  19. j = 0;
  20. k = l;
  21. while (i < n1 && j < n2)
  22. {
  23. if (L[i] <= R[j])
  24. {
  25. arr[k] = L[i];
  26. i++;
  27. }
  28. else
  29. {
  30. arr[k] = R[j];
  31. j++;
  32. }
  33. k++;
  34. }
  35.  
  36. /* Copy the remaining elements of L[], if there are any */
  37. while (i < n1)
  38. {
  39. arr[k] = L[i];
  40. i++;
  41. k++;
  42. }
  43.  
  44. /* Copy the remaining elements of R[], if there are any */
  45. while (j < n2)
  46. {
  47. arr[k] = R[j];
  48. j++;
  49. k++;
  50. }
  51. }
  52.  
  53. void mergeSort(int arr[],int l,int r)
  54. {
  55. if(l < r)
  56. {
  57. int m = l+(r-l)/2;
  58. mergeSort(arr, l, m);
  59. mergeSort(arr, m+1, r);
  60. merge(arr, l, m, r);
  61.  
  62. }
  63. }
  64. int main()
  65. {
  66. int t,n,i;
  67. int *a;
  68. scanf("%d",&t);
  69. while(t--)
  70. {
  71. scanf("%d",&n);
  72. a = (int*)malloc(sizeof(int)*n);
  73. for(i=0;i<n;i++)
  74. scanf("%d",&a[i]);
  75. int max,index=0;
  76. int count[10001] = {0};
  77. mergeSort(a,0,n-1);
  78. for(i=0;i<n;i++)
  79. {
  80. if(a[i+1]==a[i])
  81. {
  82. count[a[i]]++;
  83. }
  84. }
  85.  
  86. max = count[0];
  87. for(i=1;i<10001;i++)
  88. {
  89.  
  90. if(count[i]>max)
  91. {
  92. max = count[i];
  93. index = i;
  94. }
  95. }
  96. printf("%d %d\n",index,max+1);
  97.  
  98. }
  99.  
  100. return 0;
  101. }
  102.  
Success #stdin #stdout 0s 2144KB
stdin
1
1 1
stdout
0 1