데이터 구조 가 무도회 문 제 를 실현 하 다.

1979 단어
#include 
#include 
#include 
#include 

#define MAXSIZE 100 

typedef struct{
	char name[10];
	char team;
}Player;
typedef struct{
	Player A[MAXSIZE];
	int front;
	int rear;
}A;
typedef struct{
	Player B[MAXSIZE];
	int front;
	int rear;
}B;
void Macth(A *a,B *b,Player people[],int x){
	int i;
	for(i=1;iA[a->rear].name,people[i].name);
		a->A[a->rear].team=people[i].team;
		a->rear=(a->rear+1)%MAXSIZE;	
		}
		else if(people[i].team=='B'){
		strcpy(b->B[b->rear].name,people[i].name);
		b->B[b->rear].team=people[i].team;
		b->rear=(b->rear+1)%MAXSIZE;
		}
	}
}
void JoinMacth(A *a,B *b){
	while(a->rear!=a->front&&b->rear!=b->front){
	    printf("A  %s————B  %s
",a->A[a->front].name,b->B[b->front].name); a->front=(a->front+1)%MAXSIZE; b->front=(b->front+1)%MAXSIZE; } } void Judge(A *a,B *b){ int flag; if(a->front==a->rear&&b->front==b->rear) printf(" !"); else{ if(a->front!=a->rear){ flag=(a->rear+MAXSIZE-a->front)%MAXSIZE; printf("A %d !",flag); printf(" :%s",a->A[a->front].name); } else{ flag=(b->rear+MAXSIZE-b->front); printf("B %d !",flag); printf(" :%s",b->B[b->front].name); } } } // , int main(){ int x,i; Player people[100]; A *a; B *b; a=(A*)malloc(sizeof(A)); b=(B*)malloc(sizeof(B)); printf(" :"); scanf("%d",&x); a->front=a->rear=0; b->front=b->rear=0; for(i=1;i<=x;i++){ printf(" *** *** ***
"); scanf("%s",people[i].name); scanf("%d",&people[i].team); if(i==x-1) printf(" !
"); } Macth(a,b,people,x); JoinMacth(a,b); Judge(a,b); }

좋은 웹페이지 즐겨찾기