| 1 2 |
| +---+---+ |
| |0 /|0 /| |
| | / | / |2|
| |/ 2|/ 4| |
| +---+---+ |
| |0 /|1 /| |
| | / | / |7|
|3|/ 7|/ 4| |
| +---+---+ |
|/ 2 / 4 |
+-----------+ Note that in the top-right grid of the lattice, the product 2 * 2 = 04 is displayed with the zero for the tens digit. However, there is no thousands digit displayed in the product 324, nor is there any slash displayed above the digit 3 in that product.
?
Input
The input contains one or more tests. Each test contains two positive integers, A and B, such that 1 ≤ A ≤ 9999 and 1 ≤ B ≤ 9999. The last data set will be followed by a line containing 0 0.
Output
For each data set, produce the grid that illustrates how to multiply the two numbers using the lattice multiplication technique.
Sample Input
345 56 12 27 1 68 9999 7 3 3 0 0
Sample Output
+---------------+ | 3 4 5 | | +---+---+---+ | | |1 /|2 /|2 /| | | | / | / | / |5| |1|/ 5|/ 0|/ 5| | | +---+---+---+ | |/|1 /|2 /|3 /| | | | / | / | / |6| |9|/ 8|/ 4|/ 0| | | +---+---+---+ | |/ 3 / 2 / 0 | +---------------+ +-----------+ | 1 2 | | +---+---+ | | |0 /|0 /| | | | / | / |2| | |/ 2|/ 4| | | +---+---+ | | |0 /|1 /| | | | / | / |7| |3|/ 7|/ 4| | | +---+---+ | |/ 2 / 4 | +-----------+ +-------+ | 1 | | +---+ | | |0 /| | | | / |6| | |/ 6| | | +---+ | | |0 /| | | | / |8| |6|/ 8| | | +---+ | |/ 8 | +-------+ +-------------------+ | 9 9 9 9 | | +---+---+---+---+ | | |6 /|6 /|6 /|6 /| | | | / | / | / | / |7| |6|/ 3|/ 3|/ 3|/ 3| | | +---+---+---+---+ | |/ 9 / 9 / 9 / 3 | +-------------------+ +-------+ | 3 | | +---+ | | |0 /| | | | / |3| | |/ 9| | | +---+ | | 9 | +-------+
HINT
?
The tables must be formatted precisely as outlined by the rules and examples provided. Mistakes that involve solely errant whitespace will be categorized as Presentation Error; all other errors will be reported as Wrong Answer.
?
#includeconst int N =100; int main() { int A,B,C,a[N],b[N],c[N],lenA,lenB,lenC,flag; while(scanf("%d%d",&A,&B)>0) { if(A==0&&B==0) break; C=A*B; lenA=lenB=lenC=0; while(A) { a[++lenA]=A%10; A/=10; } while(B) { b[++lenB]=B%10; B/=10; } while(C) { c[++lenC]=C%10; C/=10; } for(int i=1,j=lenA;i 0;i--) for(int j=1;j<=4;j++) { printf("|"); if(j!=2) { if(j!=4||lenC-lenA i)printf("/"); else printf(" "); } if(j==1) { printf("+"); for(int e=1;e<=lenA;e++) printf("---+"); printf(" |\n"); } else if(j==2) { for(int e=1;e<=lenA;e++) printf("|%d /",(a[e]*b[i])/10); printf("| |\n"); } else if(j==3) { for(int e=1;e<=lenA;e++) printf("| / "); printf("|%d|\n",b[i]); } else { for(int e=1;e<=lenA;e++) printf("|/ %d",(a[e]*b[i])%10); printf("| |\n"); } } printf("| +"); for(int e=1;e<=lenA;e++) printf("---+"); printf(" |\n"); printf("|"); if(flag>lenA) printf("/"); else printf(" "); while(lenC) { printf(" %d ",c[lenC--]); if(lenC) printf("/"); } printf(" |\n"); printf("+-"); for(int i=1;i<=lenA;i++) printf("----"); printf("--+\n"); } }
<=lena;i++) d=" "><=lena;i++) d="">
?