程序无法运行,求C大神过目
本人小菜,写这道题,但程序无法运行,望高人指教,不胜感激。http://cogs.yeefan.us/cogs/problem/problem.php?pid=1554#include<stdio.h>
#include<string.h>
struct card{
char suit;
char rank;
};
card pile[52][52];
int main()
{
while(1)
{
int top[52];
int i;
char temp[2];
memset(top,0,sizeof(top));
scanf("%s",temp);
if(temp[0]=='#') return 0;
pile[0][top[0]].rank=temp[0];
pile[0][top[0]++].suit=temp[1];
for(i=1;i<52;i++)
{
scanf("%s",temp);
pile[i][top[i]].rank=temp[0];
pile[i][top[i]++].suit=temp[1];
}
int able = 1;
while(able)
{for(i=0;i<52;i++)
{int k = 0;
able = 0;
if(top[i] == 0)
{k++;
continue;
}
printf("%c",pile[i-3-k][top[i-3-k]].suit);
if(pile[i][top[i]].suit == pile[i-3-k][top[i-3-k]].suit || pile[i][top[i]].rank == pile[i-3-k][top[i-3-k]].rank)
{top[i-3-k]++;
pile[i-3-k][top[i-3-k]] = pile[i][top[i]];
top[i]--;
able++;
break;
}
if(pile[i][top[i]].suit == pile[i-1-k][top[i-1-k]].suit || pile[i][top[i]].rank == pile[i-1-k][top[i-1-k]].rank)
{
top[i-1-k]++;
pile[i-1-k][top[i-1-k]] = pile[i][top[i]];
top[i]--;
able++;
break;
}
}
}
int output[52];
int count = 0;
for(i=0;i<52;i++)
{
if(top[i] != 0)
output[count++] = top[i];
}
if(count - 1 == 1)
printf("1 pile remaining: 52");
else
{
printf("%d piles remaining:",count - 1);
for(i = 0;i<=count-1;i++)
printf(" %d",output[i]);
}
}
return 0;
}