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".
Input
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.
Output
For each test case, output an integer that how many possible numbers should be the LEDs described by the input in a single line.
Sample Input
2 a------ --c--f- --c--f- -1
Sample Output
Case 1: 4
#include<cstdio>
#include<cstring>
using namespace std;
char map[10][10]={"abc-efg","--c--f-","a-cde-g","a-cd-fg","-bcd-f-","ab-d-fg","ab-defg","a-c--f-","abcdefg","abcd-fg"};
char book[10];
char s[10];
int main(){
int n;
int cnt=0;
while(scanf("%d",&n)){
if(n==-1) break;
scanf("%s",book);
long long ans=1;
for(int k=1;k<=n;k++){
int t=0;
scanf("%s",s);
for(int i=0;i<=9;i++){
bool flag=true;
for(int j=0;j<7;j++){
if(map[i][j]!='-'&&s[j]=='-'&&book[j]=='-'){//这个位置应该亮,但是没亮,而且也没坏
flag=false;
break;
}
if(map[i][j]=='-'&&s[j]!='-'){//这个位置不应该亮,但是亮了
flag=false;
break;
}
}
if(flag) t++;
}
ans*=t;
}
printf("Case %d: %lld\n",++cnt,ans);
}
return 0;
}