Advertisement
a53

serbare3

a53
Feb 9th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <fstream>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. ifstream fin("serbare.in");
  6. ofstream fout("serbare.out");
  7. struct copil
  8. {
  9. char p[51];
  10. int h;
  11. } v[101];
  12. int cond(copil a, copil b)
  13. {
  14. if(a.h>b.h)return 0;
  15. else if(a.h==b.h&&strcmp(a.p,b.p)>0)return 0;
  16. return 1;
  17. }
  18. int cond1(copil a, copil b)
  19. {
  20. if(a.h<b.h)return 0;
  21. else if(a.h==b.h&&strcmp(a.p,b.p)>0)return 0;
  22. return 1;
  23. }
  24. int n, i,j, k, fr[151], frmax, cer,hmax,x,y,ult;
  25. int main()
  26. {
  27. fin>>cer;
  28. fin>>n;
  29. for(i=1; i<=n; i++)
  30. {
  31. fin>>v[i].p>>v[i].h;
  32. if(v[i].h>hmax)hmax=v[i].h;
  33. fr[v[i].h]++;
  34. if(fr[v[i].h]>frmax)
  35. frmax=fr[v[i].h];
  36. }
  37. if(cer==1)
  38. {
  39. fout<<frmax;
  40. fout<<'\n';
  41. }
  42. else
  43. {
  44. k=n-fr[hmax];
  45. x=0;
  46. ult=0;
  47. for(i=1; i<hmax; i++)
  48. if(fr[i])
  49. if(fr[i]+x<(k+1)/2)
  50. {
  51. ult=i,x=x+fr[i];
  52. }
  53. else
  54. {
  55. ult=i,x=x+fr[i];
  56. break;
  57. }
  58. y=n-x-fr[hmax];
  59. sort(v+1,v+n+1,cond);
  60. if(cer==2)
  61. {
  62. for(i=1; i<=ult; i++)
  63. for(j=1; j<=fr[i]; j++)
  64. fout<<i<<' ';
  65. for(j=1; j<=fr[hmax]; j++)
  66. fout<<hmax<<' ';
  67. for(i=hmax-1; i>=ult+1; i--)
  68. for(j=1; j<=fr[i]; j++)
  69. fout<<i<<' ';
  70. }
  71. else
  72. {
  73. for(i=1; i<=x; i++)
  74. fout<<v[i].p<<' ';
  75. for(i=n-fr[hmax]+1; i<=n; i++)
  76. fout<<v[i].p<<' ';
  77. sort(v+1,v+n+1,cond1);
  78. for(i=fr[hmax]+1; i<=fr[hmax]+y; i++)
  79. fout<<v[i].p<<' ';
  80.  
  81. }
  82. }
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement