Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的代码 比较中规中矩

Posted by 201101050424 at 2011-12-22 20:17:04 on Problem 1214
#include <stdio.h>
#include <string.h>
int top[52];
int i;
int x;
struct poker
{
	char suit;
	char rank;
};
struct poker a[52][52];
int compare()
{
	int flag1=0;
	int flag2=0;
	int flag3=0;
	int j,k,m;
	if(i==0||top[i]==-1)
	{
		return -10;
	}
	for(j=i-1;j>=0;j--)
	{
		if(top[j]!=-1)
		{
			flag1=1;
			break;
		}
	}
	for(m=j-1;m>=0;m--)
	{
		if(top[m]!=-1)
		{
			flag2=1;
			break;
		}
	}
	for(k=m-1;k>=0;k--)
	{

		if(top[k]!=-1)
		{
			flag3=1;
			break;
		}
	}
	if(flag2==1&&flag1==1&&flag3==1)
	{
		if(a[i][top[i]].suit==a[k][top[k]].suit||a[i][top[i]].rank==a[k][top[k]].rank)
		{
			return k;
		}
	}
	if(flag1==1)
	{
		if(a[i][top[i]].suit==a[j][top[j]].suit||a[i][top[i]].rank==a[j][top[j]].rank)
		{
			return j;
		}
	}
	return -10;
}
int main()
{
	int total;
	int m;

	for(i=0;i<52;i++)
	{
		scanf("%c",&a[i][0].rank);
		if(a[0][0].rank=='#')
		{
		    break;
		}
		scanf("%c",&a[i][0].suit);
		getchar();
	}
	while(a[0][0].rank!='#')
	{
		memset(top,0,sizeof(top));
		total=0;
		for(i=1;i<52;)
		{
			x=compare();
			if(x==-10)
			{
				i++;
				continue;
			}
			else
			{
				top[x]++;
				a[x][top[x]].suit=a[i][top[i]].suit;
				a[x][top[x]].rank=a[i][top[i]].rank;
				top[i]--;
				i=x;
			}

		}
		for(i=0;i<52;i++)
		{
			if(top[i]!=-1)
			{
				total++;
			}
		}
		if(total==1)
		{
		    printf("%d piles remaining:",total);
		}
		else
		{
            printf("%d piles remaining:",total);
		}
		for(i=0;i<52;i++)
		{
			if(top[i]!=-1)
			{
			    printf(" %d",top[i]+1);

			}
		}
		printf("\n");
        for(i=0;i<52;i++)
        {
            scanf("%c",&a[i][0].rank);
            if(a[0][0].rank=='#')
            {
                break;
            }
            scanf("%c",&a[i][0].suit);
            getchar();
            for(m=1;m<top[i];m++)
            {
                a[i][m].rank='\0';
                a[i][m].suit='\0';
            }
        }
	}
	return 0;
}



1 piles remaining: 52   这个注点意

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator