avatar
P00RN C-Px CH11LD

xesigev998 136 10th Jun, 2025

#include<stdio.h>
#include<string.h>

typedef struct DoiBong{
	char Ten[50];
	int SoThanhVien, Diem;
}DoiBong;
void Nhap(int n, DoiBong DS[]);

void Xuat(int n,DoiBong DS[]);
void SortDiem(int n, DoiBong DS[]);
void SortSoThanhVien(int n, DoiBong DS[]);
void SortABC(int n,DoiBong DS[]);
void Search(int n,DoiBong DS[],char Key[50]);
int SumDiem(int n, DoiBong DS[]);
int main(){
    DoiBong DS[100];
    int n;
    char Key[50];
    printf("Ban muon nhap bao nhie doi bong: ");
    scanf("%d", &n);
   Nhap(n,DS);
   SortSoThanhVien(n,DS);
   printf("\n***Top 3 So Thanh Vien:***\n");
   Xuat(3,DS);
   SortDiem(n,DS);
   printf("\n***Top 3 Diem:***\n");
   Xuat(3,DS);
   SortABC(n,DS);
   printf("\n***Sort ABC:***\n");
   Xuat(n,DS);
   printf("Nhap ten Doi Bong ban muon tim: ");
   fflush(stdin);
   gets(Key);
   Search(n,DS,Key);
   printf("Tong Diem cua cac Doi Bong: %d\n",SumDiem(n,DS));

}
void Nhap(int n,DoiBong DS[]){
	//Nhap
	printf("Nhap thong tin cac Doi Bong:\n");
    for(int i=0; i<n; i++){
    	printf("- Doi Bong thu %d:\n",i+1);
    	printf("  + Ten: ");
    	fflush(stdin);
    	gets(DS[i].Ten);
    	printf("  + So Thanh Vien: ");
    	scanf("%d",&DS[i].SoThanhVien);
    	printf("  + Diem: ");
    	scanf("%d",&DS[i].Diem);
    }
}

void Xuat(int n,DoiBong DS[]){
	 //Xuat
    for(int i=0; i<n; i++){
    	printf("\n- Top %d:\n",i+1);
    	printf("  + Ten: ");
    	puts(DS[i].Ten);
    	printf("  + So Thanh Vien: %d\n",DS[i].SoThanhVien);
    	printf("  + Diem: %d\n", DS[i].Diem);
    }
}
void SortDiem(int n, DoiBong DS[]){
	DoiBong t;
	for(int i=0; i<n-1; i++){
		for(int j=0; j<(n-1-i); j++){
			if(DS[j].Diem < DS[j+1].Diem){
				t = DS[j];
				DS[j] = DS[j+1];
				DS[j+1] = t;
			}
		}
	}
}
void SortSoThanhVien(int n, DoiBong DS[]){
	DoiBong t;
	for(int i=0; i<n-1; i++){
		for(int j=0; j<(n-1-i); j++){
			if(DS[j].SoThanhVien < DS[j+1].SoThanhVien){
				t = DS[j];
				DS[j] = DS[j+1];
				DS[j+1] = t;
			}
		}
	}
}
void SortABC(int n,DoiBong DS[]){
	DoiBong t;
	for(int i=0; i<n-1; i++){
		for(int j=0; j<(n-1-i); j++){
			if(strcmp(DS[j].Ten,DS[j+1].Ten)>0){
				t = DS[j];
				DS[j] = DS[j+1];
				DS[j+1] = t;
			}
		}
	}
}

void Search(int n,DoiBong DS[],char Key[50]){
	printf("Search Results:\n");
	for(int i=0; i<n; i++){
		if(strcmp(DS[i].Ten,Key)==0){
			printf(" + Ten: ");
    		puts(DS[i].Ten);
	    	printf(" + So Thanh Vien: %d\n",DS[i].SoThanhVien);
  	  	printf(" + Diem: %d\n", DS[i].Diem);
  	  	break;
		}else if ((i==n-1)&&(strcmp(DS[i].Ten,Key)!=0)){
			printf(" Null!\n");
		}
	}
}
int SumDiem(int n, DoiBong DS[]){
	int Sum=0;
	for(int i=0; i<n; i++){
		Sum = Sum + DS[i].Diem;
	}
	return Sum;
}
Markup
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data