Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef struct tes{
- char nama[16];
- int waktu;
- int skor;
- int ac;
- }tes;
- void urut( int awal, int akhir, struct tes sb[], int kode)
- {
- //printf("%d%d\n",awal,akhir);
- tes temp;
- int i, mot= akhir;
- for(i=awal;i<mot;i++)
- {
- if (mot<0) break;
- if((kode==1 && sb[i].ac<sb[mot].ac)
- ||(kode==2 && sb[i].waktu>sb[mot].waktu && sb[i].ac==sb[mot].ac)
- ||(kode==3 && sb[i].skor>sb[mot].skor&& sb[i].ac==sb[mot].ac && sb[i].waktu==sb[mot].waktu)
- ||(kode==4 && strcmp(sb[i].nama,sb[mot].nama)>0))
- {
- temp=sb[i];
- sb[i]=sb[mot-1];
- sb[mot-1]=sb[mot];
- sb[mot]=temp;
- i--; mot--;
- //printf("%d%d\n",i,mot);
- }
- }
- // for(i=0;i<akhir;i++)
- // printf("%s\n",sb[i].nama);
- if (mot-1-awal > 0) urut(awal,mot-1,sb,kode);
- if( akhir - (mot+1) > 0) urut(mot+1,akhir, sb,kode);
- }
- int main(){
- int n,i,j,con,i1,n1,w,k, tanda=0;
- char nama[100];
- int ac,waktu,skor,ac1,waktu1,skor1;
- scanf("%d",&n);
- tes sb[n];
- for(i=0;i<n;i++){
- //getchar();
- scanf("%s%d%d%d", nama,&ac,&waktu, &skor);
- strcpy(sb[i].nama,nama);
- sb[i].ac=ac; sb[i].waktu=waktu; sb[i].skor=skor;
- }
- // for(i=0;i<n;i++)
- // printf("%s\n",sb[i].nama);
- for(w=1;w<=4;w++){
- con=0;
- if(w==1)
- {
- //printf("1");
- urut(0,n-1,sb,w);
- }
- else if (w==2)
- {
- // printf("2");
- con=sb[0].ac;
- i=0;j=0;
- for(k=0;k<n;k++){
- if(sb[k].ac==con) j++;
- else
- {
- //printf("2.");
- urut(i,j-1,sb,w); i=j; con=sb[k].ac;k--;
- }
- } urut(i,j-1,sb,w);
- }
- else if (w==3)
- {
- // printf("3");
- con=sb[0].waktu;
- i=0;j=0;
- for(k=0;k<n;k++){
- if(sb[k].waktu==con) j++;
- else
- {
- // printf("3.");
- urut(i,j-1,sb,w); i=j; con=sb[k].waktu;k--;
- }
- } urut(i,j-1,sb,w);
- }
- else if (w==4)
- {
- // printf("4");
- skor1=sb[0].skor;
- ac1=sb[0].ac;
- waktu1=sb[0].waktu;
- i=0;j=0;
- for(k=0;k<n;k++)
- {
- // printf("%d",k);
- if(sb[k].skor== skor1 && sb[k].ac==ac1 && sb[k].skor==skor1) j++;
- else
- {
- // printf("4.");
- urut(i,j-1,sb,w); i=j;
- skor1=sb[k].skor;
- ac1=sb[k].ac;
- waktu1=sb[k].waktu;
- k--;
- }
- }
- urut(i,j-1,sb,w);
- }
- }
- for(i=0;i<n;i++)
- printf("%s\n",sb[i].nama);
- return 0;
- }
- /*
- 6
- palingjago 4 100 20
- jagobanget 4 90 25
- agakjago 4 90 20
- biasaaja 3 100 0
- acsemua 3 100 10
- semogaac 0 0 0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement