1、http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2958
2、题目:
To our acknowledgement, numbers can be displayed on computer screen as below, from 0 to 9:
._. ... ._. ._. ... ._. ._. ._. ._. ._. |.| ..| ._| ._| |_| |_. |_. ..| |_| |_| |_| ..| |_. ._| ..| ._| |_| ..| |_| ._|
As you can see, vertical bars and horizontal bars descript digits.
This technology has been used in Cheer bank today. The bank use optical scanner to read the accounts of checks, and display them on computer screen. But there is something wrong with the optical scanner, sometimes it recognizes bars (either vertical or horizontal) as dots. This makes some digit incorrect. To cope with such situation, the bank uses checksum.
The account in a check will always has 9 digit, namely, d1, d2, d3, ..., d9. We consider the account read by the scanner correct if
(9d1 + 8d2 + 7d3 + ... + d9) mod 11 = 0
You are to write a program to detect errors and try to correct them.
Note: Error seldom occurs. So if this does happen, at most 1 digit would be incorrect.
Input
There are multiple test cases for this problem.
There are three lines for each test. Each line contains 27 characters, with no leading and tailing spaces. And you can assume that there is no malformed input, errors will just replace bars with dots.
Output
Output the actual account for each test case if there is no error or the error can be corrected. If you can't find any solution, output "failure". If you can find more than one solution, output "ambiguous".
Sample Input
...._.._....._.._.._.._.._. ..|._|._||_||_.|_...||_||_| ..|._.._|..|._||_|..||_|._| ._.._.._.._.._.._.._.._.._. |_||_||_||_||_||_||_||_||_| |_||_||_||_||_||_||_||_||_| ...._.._.._.._.._.._....._. |_||_||.||.||_...|..|..||_. ..|._||_||_||_|..|..|..|._| ._....._.._.._.._.._.._.._. |_|..||_||_||_||_||_||_||_| |_|..||_||_||_||_||_||_||_|
Sample Output
123456789 failure ambiguous 878888888
Hint
The solution for the first sample should be 123456789 because the second digit can be 2 or 3, but if it is 3, checksum will not be satisfied. And the fifth digit can be 5 or 6, but if the fifth digit is 6, there will be 2 two incorrect digits, this violates the rule: "at most 1 digit would be incorrect".
3、wrong answer代码:
#include<stdio.h>
#include<string.h>
char str1[30];
char str2[30];
char str3[30];
char str[5][5];
int ans[10];
int pos;
int change(char s[][5])
{
if(s[0][0]=='.'&&s[0][1]=='_'&&s[0][2]=='.'&&s[1][0]=='|'&&s[1][1]=='.'&&s[1][2]=='|'&&s[2][0]=='|'&&s[2][1]=='_'&&s[2][2]=='|')
return 0;
else if(s[0][0]=='.'&&s[0][1]=='.'&&s[0][2]=='.'&&s[1][0]=='.'&&s[1][1]=='.'&&s[1][2]=='|'&&s[2][0]=='.'&&s[2][1]=='.'&&s[2][2]=='|')
return 1;
else if(s[0][0]=='.'&&s[0][1]=='_'&&s[0][2]=='.'&&s[1][0]=='.'&&s[1][1]=='_'&&s[1][2]=='|'&&s[2][0]=='|'&&s[2][1]=='_'&&s[2][2]=='.')
return 2;
else if(s[0][0]=='.'&&s[0][1]=='_'&&s[0][2]=='.'&&s[1][0]=='.'&&s[1][1]=='_'&&s[1][2]=='|'&&s[2][0]=='.'&&s[2][1]=='_'&&s[2][2]=='|')
return 3;
else if(s[0][0]=='.'&&s[0][1]=='.'&&s[0][2]=='.'&&s[1][0]=='|'&&s[1][1]=='_'&&s[1][2]=='|'&&s[2][0]=='.'&&s[2][1]=='.'&&s[2][2]=='|')
return 4;
else if(s[0][0]=='.'&&s[0][1]=='_'&&s[0][2]=='.'&&s[1][0]=='|'&&s[1][1]=='_'&&s[1][2]=='.'&&s[2][0]=='.'&&s[2][1]=='_'&&s[2][2]=='|')
return 5;
else if(s[0][0]=='.'&&s[0][1]=='_'&&s[0][2]=='.'&&s[1][0]=='|'&&s[1][1]=='_'&&s[1][2]=='.'&&s[2][0]=='|'&&s[2][1]=='_'&&s[2][2]=='|')
return 6;
else if(s[0][0]=='.'&&s[0][1]=='_'&&s[0][2]=='.'&&s[1][0]=='.'&&s[1][1]=='.'&&s[1][2]=='|'&&s[2][0]=='.'&&s[2][1]=='.'&&s[2][2]=='|')
return 7;
else if(s[0][0]=='.'&&s[0][1]=='_'&&s[0][2]=='.'&&s[1][0]=='|'&&s[1][1]=='_'&&s[1][2]=='|'&&s[2][0]=='|'&&s[2][1]=='_'&&s[2][2]=='|')
return 8;
else if(s[0][0]=='.'&&s[0][1]=='_'&&s[0][2]=='.'&&s[1][0]=='|'&&s[1][1]=='_'&&s[1][2]=='|'&&s[2][0]=='.'&&s[2][1]=='_'&&s[2][2]=='|')
return 9;
else
{
return 10;
}
}
int change2(int c)
{
if(c==0)
return 8;
else if(c==1)
return 7;
else if(c==3)
return 9;
else if(c==5)
return 13;
else if(c==6)
return 8;
else if(c==9)
return 8;
else
return c;
}
int add(int b[10])
{
if((9*b[0]+8*b[1]+7*b[2]+6*b[3]+5*b[4]+4*b[5]+3*b[6]+2*b[7]+b[8])%11==0)
return 1;
else
return 0;
}
int main()
{
int k;
int a[10];
while(scanf("%s",str1)!=EOF)
{
int flag=0,flag1=0;
memset(a,0,sizeof(a));
scanf("%s",str2);//printf("%s\n",str2);
scanf("%s",str3);
//printf("%s\n",str3);
k=0;
for(int i=0; i<27; i=i+3)
{
str[0][0]=str1[i];
str[0][1]=str1[i+1];
str[0][2]=str1[i+2];
str[1][0]=str2[i];
str[1][1]=str2[i+1];
str[1][2]=str2[i+2];
str[2][0]=str3[i];
str[2][1]=str3[i+1];
str[2][2]=str3[i+2];
a[k++]=change(str);
if(a[k-1]==10)
{
flag=1;
flag1=k-1;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
if(str[i][j]=='.')
{
str[i][j]='_';
int n=change(str);
str[i][j]='.';
if(n>=0&&n<=9)
ans[pos++]=n;
str[i][j]='|';
n=change(str);
if(n>=0&&n<=9)
ans[pos++]=n;
str[i][j]='.';
}
}
}
}
}
int count=0;
if(add(a))
{
for(int i=0; i<9; i++)
printf("%d",a[i]);
printf("\n");
}
else
{
int pp,qq,pq;
if(flag==1)
{
for(int i=0; i<pos; i++)
{
a[flag1]=ans[i];
if(add(a)==1)
{
pp=ans[i];
count++;
}
}
if(count==0)
printf("failure\n");
else if(count==1)
{
a[flag1]=pp;
for(int i=0; i<9; i++)
printf("%d",a[i]);
printf("\n");
}
else
printf("ambiguous\n");
}
else
{
for(int i=0; i<9; i++)
{
pp=a[i];
a[i]=change2(pp);
//printf("***%d %d\n",pp,a[i]);
if(a[i]>10)
{a[i]=6;
if(add(a)==1)
{
count++;
qq=i;
pq=a[i];
}
a[i]=9;
if(add(a)==1)
{
count++;
qq=i;
pq=a[i];
}
}
else
{
if(add(a)==1)
{
count++;
qq=i;
pq=a[i];
}
}
a[i]=pp;
}
if(count==0)
printf("failure\n");
else if(count==1)
{
a[qq]=pq;
for(int i=0;i<9;i++)
printf("%d",a[i]);
printf("\n");
}
else
{
printf("ambiguous\n");
}
}
}
}
return 0;
}
/*
...._.._....._.._.._.._.._.
..|._|._||_||_.|_...||_||_|
..|._.._|..|._||_|..||_|._|
._.._.._.._.._.._.._.._.._.
|_||_||_||_||_||_||_||_||_|
|_||_||_||_||_||_||_||_||_|
...._.._.._.._.._.._....._.
|_||_||.||.||_...|..|..||_.
..|._||_||_||_|..|..|..|._|
._....._.._.._.._.._.._.._.
|_|..||_||_||_||_||_||_||_|
|_|..||_||_||_||_||_||_||_|
*/