Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- struct Date {
- int Day, Month, Year;
- };
- int Key(struct Date *date,int id)
- {
- int i;
- if(id==1)
- return date->Day-1;
- if (id==2)
- return date->Month-1;
- else
- return (date->Year)-1970;
- }
- void SortRaspr (struct Date *Mas,int nel,int (*Key)(struct Date *date,int id))
- {
- int i=0,j,k,d=4,g,sch;
- int razm;
- struct Date newm[nel];
- for (g=1;g<d;g++){
- sch=g;
- // printf("%d\n",sch);
- if (sch==1) razm=31;
- else
- if (sch==2) razm=12;
- else razm=62;
- int count[razm];
- for (i=0;i<razm;i++)
- count[i]=0;
- j=nel-1;
- while (j>=0){
- if (sch==1) k=Key(&Mas[j],sch);
- else
- if (sch==2) k=Key(&Mas[j],sch);
- else k=Key(&Mas[j],sch);
- count[k]++;
- j--;
- }
- //printf("r\n");
- //for (i=0;i<razm;i++)
- //printf("%d",count[i]);
- i=1;
- while(i<razm){
- count[i]=count[i]+count[i-1];
- i++;
- }
- j=0;
- while (j<nel){
- //
- if (sch==1)
- k=Key(&Mas[j],sch);
- else
- if (sch==2)
- k=Key(&Mas[j],sch);
- else k=Key(&Mas[j],sch);
- //
- i=count[k]-1;
- count[k]=i;
- newm[i]=Mas[j];
- j++;
- }
- }
- // for(i=0;i<nel;i++)
- // printf("%d %d %d\n", newm[i].Year, newm[i].Month, newm[i].Day);
- for (i=nel-1;i>=0;i--)
- Mas[i]=newm[i];
- }
- int main()
- {
- int N,i,nach;
- scanf("%d",&N);
- struct Date MasDat[N];
- for(i=0;i<N;i++)
- scanf("%d%d%d", &MasDat[i].Year, &MasDat[i].Month, &MasDat[i].Day);
- SortRaspr(MasDat,N,Key);
- for(i=0;i<N;i++)
- printf("%d %d %d\n", MasDat[i].Year, MasDat[i].Month, MasDat[i].Day);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement