-
matrix+file
The BTR Bank began using a new scanner to process the checks used. The scanner converts the horizontal and vertical lines of the numbers into ASCII symbols '|' (ASCII code 124) and '_' (code 95).
Thus, after scanning, a sequence of vertical, horizontal lines and spaces is formed. It is known that each check has a number of 9 digits and for each number the condition is fulfilled: (d1 + 2*D2 + ... + 9*D9) mode 11 = 0, where di is a number of the number. Numbers are numbered from right to left: d9d8d7d6d5d4d3d2d1.
There are errors in the scanning process.
Write a program that determines the correct number of the check if it is known that:
• If the read number is admissible for the check, then it is correct;
• Erroneously read no more than one digit;
• No additional lines appear on scanning.
input
The input file contains the scanned image of height 3 and length of 27 symbols. Each figure occupies a 3 × 3 square.
output
The file contains either the correct number of the check or the failure message, if the number can not be restored, or the ambiguous message if there are several solutions.
_ _ _ _ _ _ _
| _ | _ || _ || _ | _ || _ || _ |
|| _ _ | | | _ || _ | || _ | _ |
Example output
123456789
-
can somebody help me, please
-
Help you with what? You haven't asked any questions, all you have done is post the assignment. You need to post the code that you've written and then ask specific questions about that code.
Also you need to post a small sample of your input file, within code tags to preserve spacing.
-
So what are you stuck on?
Reading a single line from a file?
Reading three lines from a file?
Extracting 3x3 cells from three lines?
Show some effort to the point where you're stuck, then we'll help.
This isn't a homework on demand service where you can dump your assignment and get a ready made answer.
-
insert
Code:
#include<stdio.h>
int main(){
FILE *f,*f1;
int i, j;
f = fopen("problema29.txt", "r");
if (f==NULL) perror("error opening file");
else{}
char a[3][27];
f1=fopen("output.txt","w");
for (i = 0; i < 3; i++)
for(j = 0;j<27;j++) { fscanf(f, "%c", &a[i][j]);
if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]==' ' && a[i+1][j+2]=='|' && a[i+2][j]=='|' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|') fprintf(f1,"%c",'0') //printf("0");
if (a[i][j]==' ' && a[i][j+1]==' ' && a[i][j+2]==' ' && a[i+1][j]==' ' && a[i+1][j+1]=='|' && a[i+1][j+2]==' ' && a[i+2][j]==' ' && a[i+2][j+1]=='|' && a[i+2][j+2]==' ') fprintf(f1,"%c",'1') //printf("1");
if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]=='|' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]==' ' && a[i+2][j]==' ' && a[i+2][j+1]=='_' && a[i+2][j+2]==' ') fprintf(f1,"%c",'2') //printf("2");
if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]==' ' && a[i+1][j+1]=='_' && a[i+1][j+2]=='|' && a[i+2][j]==' ' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|') fprintf(f1,"%c",'3') //printf("3");
if (a[i][j]==' ' && a[i][j+1]==' ' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]=='|' && a[i+2][j]==' ' && a[i+2][j+1]==' ' && a[i+2][j+2]=='|') fprintf(f1,"%c",'4') //printf("4");
if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]==' ' && a[i+2][j]==' ' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|') fprintf(f1,"%c",'5') //printf("5");
if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]==' ' && a[i+2][j]=='|' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|') fprintf(f1,"%c",'6') //printf("6");
if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]==' ' && a[i+1][j+1]==' ' && a[i+1][j+2]=='|' && a[i+2][j]==' ' && a[i+2][j+1]==' ' && a[i+2][j+2]=='|') fprintf(f1,"%c",'7') //printf("7");
if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]=='|' && a[i+2][j]=='|' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|') fprintf(f1,"%c",'8') //printf("8");
if (a[i][j]==' ' && a[i][j+1]=='_' && a[i][j+2]==' ' && a[i+1][j]=='|' && a[i+1][j+1]=='_' && a[i+1][j+2]=='|' && a[i+2][j]==' ' && a[i+2][j+1]=='_' && a[i+2][j+2]=='|') fprintf(f1,"%c",'9')//printf("9");
fclose(f);}
fclose(f1);
}
f1=fopen("output.txt","r+");
int s;
char v[9];
fscanf(f1,"%c",&v[s]);
if((v[i]+2*v[i+1]+3*v[i+2]+4*v[i+3]+5*v[i+4]+6*v[i+5]+7*v[i+6]+8*v[i+7]+9*v[i+8])%11==0){
fprintf(f1,"%c%c%c%c%c%c%c%c%c",v[i+8],v[i+7],v[i+6],v[i+5],v[i+4],v[i+3],v[i+2],v[i+1],v[i]);} else fprintf(f1,"failure");
}
this is not an exam, just a problem from my homework!
what is the next i need to do? if you want help me
-
The first thing is to comment out lines 16 to 25.
You can't begin to analyse the data until you've finished reading in all the data.
You also need to be aware that %c will read and store newlines along with your regular data, so you need to account for this as well.
Your first step should be
- read in a 3x27 matrix
- print a 3x27 matrix
Make sure your data has been read in correctly before trying to analyse it.