title: Google code jam APAC test seven segment display
body: <p>I am trying to solve <strong>Google Code Jam APAC test Seven segment display</strong> problem. 
  <strong><em><a href="https://code.google.com/codejam/contest/3214486/dashboard" rel="nofollow">https://code.google.com/codejam/contest/3214486/dashboard</a></em></strong>
  I have implemented the solution using minimum hamming distance between string consisting binary's of 98765432109876 and the given string of N.
  I am unable to understand cases when there result will be unambigious to print <strong>ERROR!</strong>.
  Here is my solution-</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstdio&gt;
  #include&lt;cstring&gt;
  #include&lt;algorithm&gt;
  using namespace std;
  int main()
  {
      int t;
      cin&gt;&gt;t;
       char str[]="111101111111111110000101111110110110110011111100111011010110000111111011110111111111111000010111111011011";
       int l=strlen(str);
  
      for(int k=1;k&lt;=t;k++)
      {
       int n;
        cin&gt;&gt;n;
         l=10*7+(n-1)*7;
        char num[50];
        for(int i=0;i&lt;7*n;i++)
        {
              char ch;
              cin&gt;&gt;ch;
              if(ch!=' ')
               num[i]=ch;
  
        }
        int ok[7]={0};
        for(int i=0;i&lt;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&lt;=(l-(7*n));i=i+7)
        {
            dt=0;
            z=0;
            memset(txor_res,0,sizeof(int)*9);
  
          for(int j=0;j&lt;7*n;j++){
              if((str[j+i]=='1'&amp;&amp;num[j]=='0'&amp;&amp;ok[j%7]==1)||(str[j+i]=='0'&amp;&amp;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&lt;mn_dst)
               {
                   mn_dst=dt;
                   dt=0;
                   pos=i;
                   for(int h=0;h&lt;=7;h++)
                   {
                     xor_res[h]=txor_res[h];
                     txor_res[h]=0;
                   }
  
               }
  
        }
  
          if(f==1||mn_dst==10000)
           cout&lt;&lt;"Case #"&lt;&lt;k&lt;&lt;": "&lt;&lt;"ERROR!\n";
          else
           {
               cout&lt;&lt;"Case #"&lt;&lt;k&lt;&lt;": ";
  
               pos=pos+7*n;
               for(int i=pos;i&lt;(pos+7);i++)
                  {
  
                        cout&lt;&lt;str[i];
                  }
           cout&lt;&lt;"\n";
           }
  
      }
  }
  </code></pre>
  
  <p><strong>I don't want to bother anyone by understanding my code.Instead I want a new approach.</strong></p>