2010年9月17日 星期五

ACM 170 - Clock Patience

#include <stdio.h>
#include <memory.h>

struct Poker
{
char points;
char color;
int isExist;
};
struct Poker p[13][4];

int main()
{
while (1)
{
char str[40];
int i, j, nIndex, k = 0, isTurn, turnCount;
char ch, nowPoints, nowColor;
for (i = 0 ; i < 4; i ++)
{
memset(str, 0, strlen(str));
gets(str);
if (str[0] == '#') break;
j = 0;
while (str[j] != '\0')
{
if (j % 3 == 0)
ch = str[j];
else if (j % 3 == 1)
{
p[(j-1)/3][k].points = ch;
p[(j-1)/3][k].color = str[j];
p[(j-1)/3][k].isExist = 1;
}
j ++;
}
k ++;
}
if (str[0] == '#') break;

nowPoints = p[0][0].points, nowColor = p[0][0].color, turnCount = 1;
p[0][0].isExist = 0;
while (1)
{
isTurn = 0;
if (nowPoints == 'A') nIndex = 12;
else if (nowPoints == 'T') nIndex = 3;
else if (nowPoints == 'J') nIndex = 2;
else if (nowPoints == 'Q') nIndex = 1;
else if (nowPoints == 'K') nIndex = 0;
else nIndex = 13 - (nowPoints - '0');

for (i = 0; i < 4; i ++)
if (p[nIndex][i].isExist)
{
p[nIndex][i].isExist = 0;
nowColor = p[nIndex][i].color;
nowPoints = p[nIndex][i].points;
isTurn = 1;
turnCount ++;
break;
}
if (!isTurn)
{
printf("%02d,%c%c\n", turnCount, nowPoints, nowColor);
break;
}
}
}
return 0;
}

回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...