U E D R , A S I H C RSS

데블스캠프2009/목요일/연습문제/다빈치코드/박준호

데블스캠프2009/목요일/연습문제/다빈치코드/박준호

#include <stdio.h>

int index = 0;
char color;
int num;
int b_block[13] = {0 , 1 , 2, 3, 4, 5, 6 , 7, 8, 9, 10, 11, -1};
int w_block[13] = {0 ,1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11 ,-1};
	int cardnum = 3;
struct hand{
	int number; 
	char color1;
};
typedef struct hand hand;
hand handsort[13];

	
void CmpColor(hand handsort[], int i);

void CmpNum();

void DrawCard(hand hand[], int index);

int main()
{


	
	

		
	for(index = 0; index <= cardnum; index++)
	{
		DrawCard(handsort,index);
	}
	
	CmpNum();
	for(index = 0; index <= cardnum; index ++)
	{
		printf("%c%d ",handsort[index].color1, handsort[index].number);
	}
	

	return 0;

}

void DrawCard(hand handsort[], int index)
{
	printf("받고 싶으신 색과 숫자를 적으시오.");
	fflush(stdin);
	scanf("%c %d", &color, &num);
	if (color == 'w'){
		handsort[index].number = w_block[num];
		handsort[index].color1 = 'w';
	}
	else if(color == 'b'){
		handsort[index].number = b_block[num];
		handsort[index].color1 = 'b';
	}
}

void CmpColor(hand handsort[],int i)
{
	char a;
	int b;
	if(handsort[i].color1 == 'w')
	{
		a = handsort[i].color1;
		handsort[i].color1 = handsort[i+1].color1;
		handsort[i+1].color1 = a;
		b = handsort[i].number;
		handsort[i].number = handsort[i+1].number;
		handsort[i+1].number = b;
	//swap		
	}
}

void CmpNum(){
	int i =0, j = cardnum;
	int a = 0;
	char b;
	for(j = (cardnum - 1); j >= 0; j--)
	{
		for(i = 0; i <= j; i++)
		{
			if(handsort[i].number >= handsort[(i+1)].number)
			{
				if(handsort[i].number == handsort[i+1].number)
				{
					CmpColor(handsort, i);
				}
				else{
					a = handsort[i].number;
					handsort[i].number =handsort[(i+1)].number;
					handsort[i+1].number = a;
					b = handsort[i].color1;
					handsort[i].color1 = handsort[i+1].color1;
					handsort[i+1].color1 = b;
				//swap
				}
			
			}					
		}

	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:09
Processing time 0.0173 sec