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

郁闷,原来把问题想得太复杂了。现在AC了,发个程序庆祝 一下

Posted by huicpc15 at 2005-11-03 21:31:38 on Problem 2694
#include <stdio.h>
int fun(char a[6][4]);
int samenum(char a[6][4]);
int samenum1(char a[6][4]);
int straight(char a[6][4]);
int SUMNUM(char a[6][4]);
int main()
{
    int W,i;
    scanf("%d",&W);
    for(i=0;i<W;i++)
    {
        int j,score;
        char a[6][4];
        for(j=1;j<=5;j++)
        {
                scanf("%s",a[j]);//puts(a[j]);    
        }
            
        score=fun(a);
        //if(!score) printf("O\n");
        //else
        printf("%d\n",score);
        
    } 
    //getchar();
   //getchar();
}

//fun
int fun(char a[6][4])
{
        int minnum=samenum1(a),maxnum=samenum(a),maxnum1=SUMNUM(a);
        //printf("samemin=%d,maxnum=%d,maxnum1=%d\n",minnum,maxnum,maxnum1);        
        if((a[1][0]==a[2][0]&&a[2][0]==a[3][0]&&a[3][0]==a[4][0]&&a[4][0]==a[5][0])&& (straight(a)))
        {
                
                  return 1000;
                
                    
        }
    else if(maxnum==4) 
        return 750;
    else if((maxnum==3)&&(minnum==2))
    {
        
          return 500;        
    }
    else if(a[1][0]==a[2][0]&&a[2][0]==a[3][0]&&a[3][0]==a[4][0]&&a[4][0]==a[5][0])
      return 350;   
    
    else if(straight(a)) 
      return 250;
    else if((maxnum==3))
      return 200;
    else if(maxnum==2&&maxnum1==2)
      return 100; 
    else if(maxnum==2&&maxnum1==1)
      return 50;
    return 0;
}

int samenum(char a[6][4])
{
    int i,j,num,max=-1;
    for(i=1;i<=5;i++)
    {
        num=1;
        for(j=1;j<=5;j++)
        {
                if(j==i) continue;
                if(a[i][1]==a[j][1]) num++;
        }
        if(num>max) max=num;            
    }
    return max;    
}
//
int samenum1(char a[6][4])
{
    int i,j,num,min=100;;
    for(i=1;i<=5;i++)
    {
        num=1;
        for(j=1;j<=5;j++)
        {
                if(j==i) continue;
                if(a[i][1]==a[j][1]) num++;
        }
        if(num<min) min=num;            
    }
    return min;    
}
//straight
int straight(char a[6][4])
{
    int t,tt,min;
                char b[6];
                for(t=1;t<=5;t++)
                {
                          if(a[t][1]>'9')
                          switch(a[t][1])
                          {
                               case 'A':a[t][1]='1';break;
                               case 'X':a[t][1]='9'+1;break;
                               case 'J':a[t][1]='9'+2;break;
                               case 'Q':a[t][1]='9'+3;break;
                               case 'K':a[t][1]='9'+4;
                          }
                          b[t]=a[t][1];          
                }
                for(t=1;t<5;t++)
                {
                   min=t;
                   for(tt=t+1;tt<=5;tt++)
                     if(b[tt]<b[min]) min=tt;
                   if(min!=t)
                   {
                       char temp=b[t];
                       b[t]=b[min];
                       b[min]=temp;                     
                    }                        
                }
                //test
               // for(t=1;t<=5;t++)
                 // printf("-%d-",b[t]-'0');
                for(t=2;t<=5;t++)
                   {
                       if((b[t]-b[t-1])==1) continue;
                        else break;
                    }
                if(t==6)
                  return 1;                      
                if(((b[1]=='1')&&(b[2]=='9'+1)&&(b[3]=='9'+2)&&(b[4]=='9'+3)&&(b[5]=='9'+4))) 
                  return 1;
                return 0;
                    
        
}

int SUMNUM(char a[6][4])
{
   int i,j,flag[6]={0};
   
   for(i=1;i<5;i++)
   {
       for(j=i+1;j<=5;j++)
       if(a[i][1]==a[j][1])
         {flag[i]=1;flag[j]=1; goto loop;}    
   }
   loop:for(i=1;i<5;i++)
   {
     if(!flag[i])
     {
         for(j=i+1;j<=5;j++)
         {
                  if(!flag[j])
                  {
                      if(a[i][1]==a[j][1]) return 2;
                  }    
         }    
     }    
     
   }
   return 1;
   
      
}

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