Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream f("serbare1.in");
  5. ofstream g("serbare1.out");
  6. int n;
  7. struct copil
  8. {
  9. char nume[256];
  10. int h;
  11. }a[101];
  12. int main()
  13. {
  14. f>>n;
  15. f.get();
  16. for(int i=0; i<n; i++)
  17. {
  18. char s[256];
  19. f.get(s,256);
  20. f.get();
  21. int x;
  22. for(int j=strlen(s)-1; j>=0; j--)
  23. {
  24. if(s[j]==' ')
  25. {
  26. x=j;
  27. break;
  28. }
  29. }
  30. strncpy(a[i].nume,s,x);
  31. int nr=0;
  32. for(int j=x+1; j<strlen(s); j++)
  33. nr=nr*10+(s[j]-'0');
  34. a[i].h=nr;
  35. }
  36. bool ok=0;
  37. do
  38. {
  39. ok=0;
  40. for(int i=0; i<n-1; i++)
  41. if(a[i].h>a[i+1].h)
  42. {
  43. swap(a[i].h,a[i+1].h);
  44. char t[256];
  45. strcpy(t,a[i].nume);
  46. strcpy(a[i].nume,a[i+1].nume);
  47. strcpy(a[i+1].nume,t);
  48. ok=1;
  49. }
  50. }while(ok);
  51. do
  52. {
  53. ok=0;
  54. for(int i=0; i<n-1; i++)
  55. if(strcmp(a[i].nume,a[i+1].nume)>0&&a[i].h==a[i+1].h)
  56. {
  57. swap(a[i].h,a[i+1].h);
  58. char t[256];
  59. strcpy(t,a[i].nume);
  60. strcpy(a[i].nume,a[i+1].nume);
  61. strcpy(a[i+1].nume,t);
  62. ok=1;
  63. }
  64. }while(ok);
  65. int verif[256],x=1;
  66. verif[0]=x;
  67. for(int i=1; i<n; i++)
  68. {
  69. if(a[i].h==a[i-1].h)
  70. verif[i]=x;
  71. else
  72. {
  73. x++;
  74. verif[i]=x;
  75. }
  76. }
  77.  
  78. g<<x;
  79. int lc=1;
  80. for(int i=n-1; i>=0; i--)
  81. {
  82. if(verif[i]==verif[i-1])
  83. {lc++;}
  84. else
  85. {
  86.  
  87. g<<'\n'<<lc<<" ";
  88. for(int j=i; j<=i+lc-1; j++)
  89. g<<a[j].nume<<" ";
  90. lc=1;
  91. }
  92. }
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement