c++ - Google code jam APAC test seven segment display -


i trying solve google code jam apac test 7 segment display problem. https://code.google.com/codejam/contest/3214486/dashboard have implemented solution using minimum hamming distance between string consisting binary's of 98765432109876 , given string of n. unable understand cases when there result unambigious print error!. here solution-

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() {     int t;     cin>>t;      char str[]="111101111111111110000101111110110110110011111100111011010110000111111011110111111111111000010111111011011";      int l=strlen(str);      for(int k=1;k<=t;k++)     {      int n;       cin>>n;        l=10*7+(n-1)*7;       char num[50];       for(int i=0;i<7*n;i++)       {             char ch;             cin>>ch;             if(ch!=' ')              num[i]=ch;        }       int ok[7]={0};       for(int i=0;i<7*n;i++)       {           ok[i%7]=ok[i%7]|(num[i]-'0');       }        int mn_dst=10000,dt=0,f=0,pos=0;       int xor_res[9]={0},txor_res[9]={0},z=0;        for(int i=0;i<=(l-(7*n));i=i+7)       {           dt=0;           z=0;           memset(txor_res,0,sizeof(int)*9);          for(int j=0;j<7*n;j++){             if((str[j+i]=='1'&&num[j]=='0'&&ok[j%7]==1)||(str[j+i]=='0'&&num[j]=='1'))             {z=1;              break;             }           if(str[j+i]!=num[j])             {dt++;              txor_res[j%7]=1;             }                                }             if(z==1)               continue;               if(dt==mn_dst)                 {f=1;                   break;                 }              if(mn_dst!=10000)              {f=1;               break;              }              if(dt<mn_dst)              {                  mn_dst=dt;                  dt=0;                  pos=i;                  for(int h=0;h<=7;h++)                  {                    xor_res[h]=txor_res[h];                    txor_res[h]=0;                  }               }        }          if(f==1||mn_dst==10000)          cout<<"case #"<<k<<": "<<"error!\n";         else          {              cout<<"case #"<<k<<": ";               pos=pos+7*n;              for(int i=pos;i<(pos+7);i++)                 {                        cout<<str[i];                 }          cout<<"\n";          }      } } 

i don't want bother understanding code.instead want new approach.

i facing same problem in understanding question you. downloaded a-small-practice.in. ran someone's correct solution , produce different outputs in following cases -

case 1

input

1 0001011 

my output -

case #18: 0100011 

correct output -

case #18: error! 

case 2

input

1 0011111 

my output -

case #27: 0011011 

correct output -

case #27: error! 

case 3

input

1 1001111 

my output -

case #66: 1001011 

correct output -

case #66: error! 

case 4

input

1 1111110 

my output -

case #73: 1111011 

correct output -

case #73: error! 

case 5

input

1 1011101 

my output -

case #74: 1011001 

correct output -

case #74: error! 

case 6

input

2 1001001 1001101 

my output -

case #77: 0000000 

correct output -

case #77: error! 

case 7

input

1 0111011 

my output -

case #81: 0111111 

correct output -

case #81: error! 

case 8

input

1 1011011 

my output -

case #94: 0110011 

correct output -

case #94: error! 

all of cases output doesn't match, because correct output "error!", while able find unambiguous next state. can or else point out why solution not unambiguous state? :) other pointers appreciated too.

let's figure out exact meaning of problem 1 case @ time :d


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -