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 yzhw at 2008-11-08 12:49:21 on Problem 1013
大家做这道题时数组一定要开的稍微大一点
比如说这道题左右砝码盘上最多有6个元素,我开了个data[6],数组,结果老是wa
把数组开到8就ac了
不知道什么原因
附代码

# include <stdio.h>
# include <string.h>
typedef struct list
{
  char left[8];
  char right[8];
}list;

list data[4];  
char ori[12];
int jishu=1;


void fillori()
{
    int i;
    for(i=0;i<12;i++)
    {
        ori[i]=i+65;
    }
}     
void add(char a[],char b[])
{
    strcpy(data[jishu].left,a);
    strcpy(data[jishu++].right,b);
}
void clean(char a)
{
 int i;
 for(i=0;i<12;i++)
 {
     if(a==ori[i])
     {
         ori[i]='Q';
         break;
     }
 }
}
int search(char c,char ins[])
{
    int i;
    for(i=0;i<strlen(ins);i++)
    {
       if(ins[i]==c) return 1;
    }
    return 0;
}   
void clean_total(int num)
{
    int i;
    char temp;
    for(i=0;i<=strlen(data[num].left);i++)
    {
     temp=data[num].left[i];
     if(search(temp,data[num].right)) clean(temp);
    }
}    
void print(char res,int jud)
{
    if(jud==0)
    {
       printf("%c is the counterfeit coin and it is heavy.\n", res);
    }
    else printf("%c is the counterfeit coin and it is light.\n", res); 
}      
void deal()
{
 int i,j;
 for(i=1;i<=jishu;i++)
 {
   clean_total(i);
 }
 for(i=0;i<12;i++)
 {
  if(ori[i]!='Q')
  {
    if(jishu==1) 
    {
     if(search(ori[i],data[1].left))  
     {
      print(ori[i],0);
     }
     else if (search(ori[i],data[1].right)) print(ori[i],1);
    }
    if(jishu==2)
    {
        if(search(ori[i],data[1].left)&&search(ori[i],data[2].left)) print(ori[i],0);
        else if(search(ori[i],data[1].right)&&search(ori[i],data[2].right)) print(ori[i],1);
    }
    if(jishu==3)        
    {
        if(search(ori[i],data[1].left)&&search(ori[i],data[2].left)&&search(ori[i],data[3].left)) print(ori[i],0);
        else if(search(ori[i],data[1].right)&&search(ori[i],data[2].right)&&search(ori[i],data[3].right)) print(ori[i],1);
    }   
  }
 }

}  
 
   
main()
{
 int i,n;
 char temp;
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  int j;
  char tdata1[10],tdata2[10];
  char tres[6];
  jishu=1;
  fillori();
  for(j=1;j<=3;j++)
  {  
    scanf("%s %s %s",tdata1,tdata2,tres);
     if(!strcmp(tres,"even"))
     {
      int k;
      for(k=0;k<strlen(tdata1);k++) clean(tdata1[k]);
      for(k=0;k<strlen(tdata2);k++) clean(tdata2[k]);
     }
     else if(!strcmp(tres,"down"))
     {
         add(tdata2,tdata1);
     }
     else add(tdata1,tdata2);
  }   
    jishu--;     
    deal();
 }
 return 0;
}              
       

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