201609(2)模擬火車購票系統

做出來之後感覺不那麼難了,廢話不多說,我要會一會爐石傳說了......TAT加油

aa

#include<stdio.h>
typedef struct index
{
 int tn;
 int aseat[6];
}Ind;

int main()
{
	Ind a[100];
	int i,j,k,count,temp;
	int pm;
	int pn;
	int seat[20][5]={0};
	//逐行打印行不通 printf("%d",seat[1]);
	int n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&temp);
		a[i].tn=temp;
	} 
	for(i=0;i<n;i++)
	{
	
		for(j=0;j<=(i+1);j++)
			for(k=0;k<(6-a[i].tn);k++)
			{
				if(seat[j][k]==0)
				{
					temp=a[i].tn;
					count=0;
					while(count<a[i].tn)
					{
						if(seat[j][k+count]==0)
							count++;			
						else
							break;
					}
					if(count==a[i].tn)
					{
						for( ;count>0;count--)
						{
							a[i].aseat[count]=j*5+k+count;
							seat[j][k+count-1]=1;	
						}					
						j=i+2;
						k=6;
					}
				}				
			}
		if(a[i].aseat[1]==0)
		{
			count=1;
			for(pm=0;pm<=19;pm++)
				for(pn=0;pn<5;pn++)
				{
					if(seat[pm][pn]==0)
					{
						a[i].aseat[count]=pm*5+pn+1;
						seat[pm][pn]==1;
						count++;
						if(count>a[i].tn)
							break;
					}
				}
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=1;j<=a[i].tn;j++)
			printf("%d ",a[i].aseat[j]);
		printf("\n");
	}		
	return 0;
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章