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 springzhe at 2006-11-28 13:31:36 on Problem 1053
In Reply To:谁能看看到底哪里错了呀?为什么总是WA? Posted by:williamzl at 2005-07-25 21:00:12
#include<iostream>
#include<string>
using namespace std;

char card[1000][20];
bool judge (int i,int j,int k) {
  int p;
  for(p=0;p<4;p++)
    if(!(
	card[i][p]==card[j][p]&&card[i][p]==card[k][p]&&card[j][p]==card[k][p]||
	card[i][p]!=card[j][p]&&card[i][p]!=card[k][p]&&card[j][p]!=card[k][p]
	)) return false;
  return true; }
int main(int) {
  int n;
  do{
    n=0;
    cin.getline(card[n++],100);
    if(!cin)break;
    while(strlen(card[n-1])==4) cin.getline(card[n++],100);
    n--;
    int i,j,k,num;
    num=0;
    cout<<"CARDS:  ";
    for(i=0;i<n;i++) cout<<' '<<card[i];         cout<<endl;
    cout<<"SETS:   ";
    for(i=0;i<n;i++)
      for(j=i+1;j<n;j++)
	for(k=j+1;k<n;k++) {
	  if(judge(i,j,k)) {
	    num++;
	    if (num>1) cout<<"        ";
	    cout<<num<<".  "<<card[i]<<' '<<card[j]<<' '<<card[k]<<endl;
	   } }
    if(num==0) {cout<<"*** None Found ***"<<endl;       }
    cout<<endl;
    }while(cin); 
return 0;}

>    if (strlen(line)!=0)
>    {  
>     sscanf(line,"%c%c%c%c",&a[i][0],&a[i][1],&a[i][2],&a[i][3]);
>     i=i+1;
>    }    
>   if (s==NULL || line[0]==0)
>      { 
>       printf ("\nCARDS:  ");
>        for (j=0;j<i;j++) 
>        { 
>         for (k=0;k<4;k++)
>           printf("%c",a[j][k]);
>         printf (" ");
>        }     
>       printf ("\nSETS:   ");
>        
>        for (j=0;j<i;j++) 
>          for (k=j+1;k<i;k++)
>            for (f=k+1;f<i;f++)
>              {
>               if ((a[j][0]!=a[k][0]&&a[j][0]!=a[f][0]&&a[k][0]!=a[f][0])||(a[j][0]==a[k][0]&&a[j][0]==a[f][0]&&a[k][0]==a[f][0])) flag=flag+1; 
>               if ((a[j][1]!=a[k][1]&&a[j][1]!=a[f][1]&&a[k][1]!=a[f][1])||(a[j][1]==a[k][1]&&a[j][1]==a[f][1]&&a[k][1]==a[f][1])) flag=flag+1; 
>               if ((a[j][2]!=a[k][2]&&a[j][2]!=a[f][2]&&a[k][2]!=a[f][2])||(a[j][2]==a[k][2]&&a[j][2]==a[f][2]&&a[k][2]==a[f][2])) flag=flag+1; 
>               if ((a[j][3]!=a[k][3]&&a[j][3]!=a[f][3]&&a[k][3]!=a[f][3])||(a[j][3]==a[k][3]&&a[j][3]==a[f][3]&&a[k][3]==a[f][3])) flag=flag+1; 
>               if (flag==4) 
>               {
>                 count++;
>                 if (count==1)printf ("%d.  ",count);else printf ("        %d.  ",count);
>                 for (t=0;t<4;t++)
>                  printf("%c",a[j][t]);
>                 printf (" "); 
>                 for (t=0;t<4;t++)
>                  printf("%c",a[k][t]); 
>                 printf (" "); 
>                 for (t=0;t<4;t++)
>                  printf("%c",a[f][t]);
>                 printf ("\n");  
>                } 
>                
>                flag=0;
>              }
>        if  (count!=0)    printf ("\n");       
>        if (count==0) printf ("*** None Found ***\n\n");
>        count=0;
>        i=0;
>        flag=0;
>   } 
>    if (s==NULL) break;
> 
> }       
>            
>              
> }               

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