Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("serbare1.in");
- ofstream g("serbare1.out");
- int n;
- struct copil
- {
- char nume[256];
- int h;
- }a[101];
- int main()
- {
- f>>n;
- f.get();
- for(int i=0; i<n; i++)
- {
- char s[256];
- f.get(s,256);
- f.get();
- int x;
- for(int j=strlen(s)-1; j>=0; j--)
- {
- if(s[j]==' ')
- {
- x=j;
- break;
- }
- }
- strncpy(a[i].nume,s,x);
- int nr=0;
- for(int j=x+1; j<strlen(s); j++)
- nr=nr*10+(s[j]-'0');
- a[i].h=nr;
- }
- bool ok=0;
- do
- {
- ok=0;
- for(int i=0; i<n-1; i++)
- if(a[i].h>a[i+1].h)
- {
- swap(a[i].h,a[i+1].h);
- char t[256];
- strcpy(t,a[i].nume);
- strcpy(a[i].nume,a[i+1].nume);
- strcpy(a[i+1].nume,t);
- ok=1;
- }
- }while(ok);
- do
- {
- ok=0;
- for(int i=0; i<n-1; i++)
- if(strcmp(a[i].nume,a[i+1].nume)>0&&a[i].h==a[i+1].h)
- {
- swap(a[i].h,a[i+1].h);
- char t[256];
- strcpy(t,a[i].nume);
- strcpy(a[i].nume,a[i+1].nume);
- strcpy(a[i+1].nume,t);
- ok=1;
- }
- }while(ok);
- int verif[256],x=1;
- verif[0]=x;
- for(int i=1; i<n; i++)
- {
- if(a[i].h==a[i-1].h)
- verif[i]=x;
- else
- {
- x++;
- verif[i]=x;
- }
- }
- g<<x;
- int lc=1;
- for(int i=n-1; i>=0; i--)
- {
- if(verif[i]==verif[i-1])
- {lc++;}
- else
- {
- g<<'\n'<<lc<<" ";
- for(int j=i; j<=i+lc-1; j++)
- g<<a[j].nume<<" ";
- lc=1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement