fork download
  1. //
  2. // main.c
  3. // NUMBERS
  4. //
  5. // Created by Dhruv Mullick on 24/11/13.
  6. // Copyright (c) 2013 Dhruv Mullick. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. struct p
  13. {
  14. long long int A;
  15. char name[6];
  16. };
  17.  
  18. void sort(struct p player[],int ibegin,int iend, struct p temp[]);
  19. void merge(struct p player[],int ibegin,int imid,int iend,struct p temp[]);
  20.  
  21. int main(void)
  22. {
  23. int n,i,c;
  24. long long int t;
  25. scanf("%d",&c);
  26.  
  27. while(c--)
  28. {
  29. scanf("%d",&n);
  30.  
  31. struct p player[n];
  32. struct p temp[n];
  33.  
  34. for(i=0;i<n;i++)
  35. {
  36. scanf("%s", player[i].name);
  37. scanf("%lld", &player[i].A);
  38. }
  39.  
  40. sort(player,0,n,temp);
  41.  
  42. for(i=0;i<n;i++)
  43. {
  44. t=player[i].A;
  45.  
  46. while(i!=n && i!=(n+1) && player[i+1].A==t)
  47. {
  48. i=i+2;
  49. }
  50.  
  51. if(i<n)
  52. {
  53. printf("%s\n",player[i].name);
  54. break;
  55. }
  56. }
  57.  
  58. if(i>=n)
  59. {
  60. printf("Nobody wins.\n");
  61. }
  62.  
  63.  
  64. }
  65.  
  66. return 0;
  67. }
  68.  
  69. void merge(struct p player[],int ibegin,int imid,int iend,struct p temp[])
  70. {
  71. int a0, a1,j;
  72. j = ibegin;
  73. a0 = ibegin;
  74. a1 = imid;
  75.  
  76. while(j<=iend)
  77. {
  78. if(a0<imid && ((a1>iend) || (player[a0].A < player[a1].A)))
  79. {
  80. temp[j]= player[a0];
  81. a0++;
  82. j++;
  83. }
  84.  
  85. else
  86. {
  87. temp[j] = player[a1];
  88. a1++;
  89. j++;
  90. }
  91. }
  92. }
  93.  
  94. void sort(struct p player[],int ibegin,int iend,struct p temp[])
  95. {
  96. int i;
  97.  
  98. if((iend - ibegin)==1)
  99. return;
  100.  
  101. int imid = (iend + ibegin)/2;
  102.  
  103. sort(player, ibegin, imid, temp);
  104. sort(player, imid, iend, temp);
  105.  
  106. merge(player, ibegin, imid, iend, temp);
  107.  
  108. for(i=ibegin;i<=iend;i++)
  109. {
  110. player[i] = temp[i];
  111. }
  112.  
  113. }
  114.  
Success #stdin #stdout 0s 2252KB
stdin
2
5
Kouta 1
Yuka 1
Mayu 3
Lucy 2
Nana 5
2
Lucy 2
Nana 2
stdout
Lucy
Nana