fork download
  1. #include <stdio.h>
  2.  
  3. int main(){
  4. int n,m,i = 0;
  5. // Takin input
  6. scanf("%d%d",&n,&m);
  7. int arr[n];
  8. for(i = 0;i<n;i++){
  9. scanf("%d",&arr[i]);
  10. }
  11. int f[m],p[m];
  12. char s[m][101];
  13.  
  14. for(i = 0;i<m;i++){
  15. scanf("%d%d",&f[i],&p[i]);
  16. scanf("%s",s[i]);
  17. }
  18. //Input taken
  19.  
  20. //Separating posts based on special friends and other friends.
  21. int j = 0,h1[n],h2[m-n],k = 0;
  22. char *a1[m],*a2[m];
  23. int v;
  24. for(i = 0;i<m;i++){
  25. for(v = 0;v<n;v++){
  26. if(f[i]==arr[v]){
  27. h1[j] = p[i];
  28. a1[j] = s[i];
  29. j++;
  30. break;
  31. }
  32. }
  33. if(v == n){
  34. h2[k] = p[i];
  35. a2[k] = s[i];
  36. k++;
  37. }
  38. }
  39.  
  40. //Then sorting the posts according to popularity and printing simultaneously.
  41. char *w;
  42. int l,z = 0,temp,max;
  43. for(i = 0;i<j;i++){
  44.  
  45. for(l = i+1;l<j;l++){
  46. if(h1[l]>h1[i]){
  47. temp = h1[l];
  48. h1[l] = h1[i];
  49. h1[i] = temp;
  50.  
  51. w = a1[l];
  52. a1[l] = a1[i];
  53. a1[i] = w;
  54. }
  55. }
  56. printf("%s\n",a1[i]);
  57. }
  58.  
  59. int x = 0;
  60. l = 0;
  61.  
  62. for(i = 0;i<k;i++){
  63.  
  64. for(l = i+1;l<k;l++){
  65. if(h2[l]>h2[i]){
  66. temp = h2[l];
  67. h2[l] = h2[i];
  68. h2[i] = temp;
  69.  
  70. w = a2[l];
  71. a2[l] = a2[i];
  72. a2[i] = w;
  73. }
  74. }
  75. printf("%s\n",a2[i]);
  76. }
  77.  
  78. return 0;
  79. }
  80.  
Success #stdin #stdout 0s 2172KB
stdin
2 4
1 2 
1 1 WhoDoesntLoveChefBook
2 2 WinterIsComing
3 10 TheseViolentDelightsHaveViolentEnds
4 3 ComeAtTheKingBestNotMiss
stdout
WinterIsComing
WhoDoesntLoveChefBook
TheseViolentDelightsHaveViolentEnds
ComeAtTheKingBestNotMiss