2014
02-12

# BrokenLED

You know, there are more and more LED Displays used for show numbers in everywhere, a general product is like the left picture below, called as 7 segments LED, because it can show all the digitals from 0 to 9 with 7 segments as the right picture below.

There are many 7 segment LED displays in our restraint, so we can view the money left in our sunny card. Unfortunately, some displays always with one or more segment are broken, that means, the segment which should be light up when it display a digital can’t work. For example, if the ‘a’ segment is broken, then ’7′ and ’1′ will be displayed as ’1′ either.
Now, Bob who is standing on front of a broken LED display want to know, how many possible results would be the number on the display. For example, with a LED display which it’s all ‘a’ segments were broken, "11" would be 4 possible results which are "11", "17", "71" and "77". Note that pre-zeros are valid, for example, "0001" is equal to "1" or "01".

There are multiply test cases, every case start with a single integers N in the first line, that is how many LED in this case, the second line is a string shows which segment is broken in the LED from ‘a’ to ‘g’, good segment will replace as ‘-’, the follow N lines will hold a string in each line to show numbers from left to right, which shows the lighted segment in the i-th LED. (1 <= N <= 9)
Input will end with a single line which N == -1.

There are multiply test cases, every case start with a single integers N in the first line, that is how many LED in this case, the second line is a string shows which segment is broken in the LED from ‘a’ to ‘g’, good segment will replace as ‘-’, the follow N lines will hold a string in each line to show numbers from left to right, which shows the lighted segment in the i-th LED. (1 <= N <= 9)
Input will end with a single line which N == -1.

2
a------
--c--f-
--c--f-
-1 

Case 1: 4

#include<iostream>using namespace std;//用位表示，如果某个显示是属于某个数字的且这个数组是属于这个显示和bug的并集//那么有可以取该中数字，这里的属于就是“|” char c[11];int a[11];//存显示的数据 int b[11];//模板 int bug;int s[11];//模板 int main(){    int i,j,k,t,r,n,count=1,len,temp,x,y;    s[1]=1;s[2]=2;s[3]=4;s[4]=8;s[5]=16;s[6]=32;s[7]=64;//abcdefg    b[0]=119;b[1]=36;b[2]=93;b[3]=109;b[4]=46;b[5]=107;b[6]=123;b[7]=37;b[8]=127;b[9]=111;    while(scanf("%d",&n)!=EOF)    {          if(n==-1)break;          memset(a,0,sizeof(a));          scanf("%s",c);          len=strlen(c);          bug=0;          for(i=0;i<len;i++)          {              if(c[i]!=’-')              {                 bug=bug+s[c[i]-’a'+1];                 }                           }    //          cout<<bug<<endl;              for(i=1;i<=n;i++)          {              scanf("%s",c);              len=strlen(c);              for(j=0;j<len;j++)              {                  if(c[j]!=’-')a[i]+=s[c[j]-’a'+1];                                }//              cout<<"a["<<i<<"]="<<a[i]<<endl;                               }             r=1;          for(i=1;i<=n;i++)          {              x=(bug|a[i]);              t=0;              for(j=0;j<=9;j++)              {                  y=(b[j]|a[i]);                  temp=(x|b[j]);                               if((y==b[j])&&(x==temp))t++;                               }                           r=r*t;                  }              printf("Case %d: %d\n",count++,r);                                           }    return 0;    }

1. 第一题是不是可以这样想，生了n孩子的家庭等价于n个家庭各生了一个1个孩子，这样最后男女的比例还是1:1