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

萌新一枚,检验答案没问题,但就是WA,好吧,记录一下

Posted by 264314 at 2018-10-06 17:14:21 on Problem 1053
# include <iostream>

using namespace std;

struct Card
{
	char ca[5]; //symbol,digit,color,shading
};

int FindSet(Card c[],Card store[][3]);
bool TypeSameOrDif(Card c,Card d,Card e,int t);
bool CardSet(Card c,Card d,Card e);

int main()
{
	Card card[12];
	Card store[250][3];
	while(cin>>card[0].ca)
	{
		if(strlen(card[0].ca) == 0) 
			continue;
		for(int i = 1;i<12;++i)
		{
			cin>>card[i].ca;
			cin.clear();
			cin.sync();
		}
		printf("CARDS:  ");
		for(int i = 0;i<12;++i)
		{
			printf("%c%c%c%c ",card[i].ca[0],card[i].ca[1],card[i].ca[2],card[i].ca[3]);
		}
		printf("\n");
		int count = FindSet(card,store) ;
		if(count == -1)
			printf("SETS:   *** None Found ***\n");
		else
		{
			printf("SETS:   1.  %s %s %s\n",store[0][0].ca,store[0][1].ca,store[0][2].ca);
			for(int i = 1;i<=count;++i)
				printf("        %d.  %s %s %s\n",i+1,store[i][0].ca,store[i][1].ca,store[i][2].ca);
		}
		printf("\n");
	}
	//system("pause");
	return 0;
}

int FindSet(Card c[],Card store[][3])
{
	int count = -1;
	for(int i = 0;i<10;++i)
		for(int j = i+1;j<11;++j)
			for(int k = j+1;k<12;++k)
				if(CardSet(c[i],c[j],c[k]))
				{
					count++;
					store[count][0] = c[i];
					store[count][1] = c[j];
					store[count][2] = c[k];
				}
	return count;
}

bool TypeSameOrDif(Card c,Card d,Card e,int t)
{
	if((c.ca[t] == d.ca[t])&&(c.ca[t] == e.ca[t])&&(d.ca[t] == e.ca[t]) || ((c.ca[t] != d.ca[t])&&(c.ca[t] != e.ca[t])&&(d.ca[t] != e.ca[t])))
		return true;
	return false;
}

bool CardSet(Card c,Card d,Card e)
{
	bool b = true;
	for(int i = 0;i<4;++i)
		b = b && TypeSameOrDif(c,d,e,i);
	return b;
}

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