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.  
  41. sort(player,0,n,temp);
  42.  
  43. for(i=0;i<n;i++)
  44. {
  45. printf("%s", player[i].name);
  46. printf("%lld", player[i].A);
  47.  
  48. printf("\n");
  49. }
  50.  
  51. for(i=0;i<n;i++)
  52. {
  53. if(i==0)
  54. {
  55. if(player[i].A==player[i+1].A)
  56. continue;
  57. else
  58. {
  59. printf("%s\n", player[i].name);
  60. break;
  61. }
  62. }
  63.  
  64. else if(i==n-1)
  65. {
  66. if(player[i].A==player[i-1].A)
  67. continue;
  68. else
  69. {
  70. printf("%s\n", player[i].name);
  71. break;
  72. }
  73. }
  74.  
  75. else
  76. {
  77. if((player[i].A == player[i+1].A) || (player[i].A==player[i-1].A))
  78. continue;
  79.  
  80. else
  81. {
  82. printf("%s\n", player[i].name);
  83. break;
  84. }
  85.  
  86. }
  87.  
  88.  
  89. }
  90.  
  91. if(i==n)
  92. printf("Nobody wins.");
  93.  
  94. }
  95.  
  96. return 0;
  97. }
  98.  
  99. void merge(struct p player[],int ibegin,int imid,int iend,struct p temp[])
  100. {
  101. int a0, a1,j;
  102. j = ibegin;
  103. a0 = ibegin;
  104. a1 = imid;
  105.  
  106. while(j<=iend)
  107. {
  108. if(a0<imid && ((a1>iend) || (player[a0].A < player[a1].A)))
  109. {
  110. temp[j]= player[a0];
  111. a0++;
  112. j++;
  113. }
  114.  
  115. else
  116. {
  117. temp[j] = player[a1];
  118. a1++;
  119. j++;
  120. }
  121. }
  122. }
  123.  
  124. void sort(struct p player[],int ibegin,int iend,struct p temp[])
  125. {
  126. int i;
  127.  
  128. if((iend - ibegin)==1)
  129. return;
  130.  
  131. int imid = (iend + ibegin)/2;
  132.  
  133. sort(player, ibegin, imid, temp);
  134. sort(player, imid, iend, temp);
  135.  
  136. merge(player, ibegin, imid, iend, temp);
  137.  
  138. for(i=ibegin;i<=iend;i++)
  139. {
  140. player[i] = temp[i];
  141. }
  142.  
  143. }
  144.  
Success #stdin #stdout 0s 2296KB
stdin
1 5 a 1 b 1 c 1 d 2 e 3
stdout
a1
b1
c1
d2
e3
d