#497566

Solution for 2102: Rummy by leafmoon

Source Code Status Test Cases
    Policy: public     Reviewed: 125    
00.00 sec    580 KB    49 lines     1009 bytes    2012-10-01 21:40
int check(char a[12]){
  int i=1;
  for(;i<10;i++){
    if(a[i]<0)return 0;
    a[i]%=3;
    if(a[i]>0){
      if(a[i+1]-a[i]<0 || a[i+2]-a[i]<0)return 0;
      a[i+1]-=a[i];a[i+2]-=a[i];a[i]=0;
    }
  }
  return 1;
}

int rummy(){
  char x[256][12];
  int hai[9];
  char color[9],c[256];
  int i;

  memset(x['R'],0,sizeof(x['R']));
  memset(x['G'],0,sizeof(x['G']));
  memset(x['B'],0,sizeof(x['B']));
  memset(hai,0,sizeof(hai));
  memset(color,0,sizeof(color));
  memset(c,0,sizeof(c));

  { //input
    for(i=0;i<9;i++)scanf("%d",hai+i); //ghaa! %d cannot be used with char array; hai has to be int array! What a shame!!! Thx K.Inaba.
    for(i=0;i<9;i++)scanf(" %c",color+i);
    for(i=0;i<9;i++){
      x[color[i]][hai[i]]++;
      c[color[i]]++;
    }
    if(c['R']%3!=0 || c['G']%3!=0 || c['B']%3!=0)return 0;
  }

  return check(x['R']) & check(x['G']) & check(x['B']);
}

int main(){
  int i=0,n,x;
  scanf("%d",&n);
  for(;i<n;i++){
    x=rummy();
    printf(x ? "1\n" : "0\n");
  }
  return 0;
}

Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 1/1 C CPU: 00.00 sec Memory: 580 KB Length: 1009 B 2012-10-01 21:40 2012-10-01 21:40
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted - -
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags