Multiplication operation is not always easy! For example, it is hard to calculate 27 × 20 using your mind, but it is easier to find the answer using the following methods: 30 × 20 - 3 × 20. It turns out that people can calculate the multiplication of two special numbers very easily.
A number is called special if it contains exactly one non-zero digit at the beginning (i.e. the most significant digit), followed by a non-negative number of zeros. For example, 30, 7, 5000 are special numbers, while 0, 11, 8070 are not.
In this problem, you are given two numbers a and b. Your task is to calculate the multiplication of a and b (a × b), by writing the multiplication expression as a summation or subtraction of multiplication of special numbers. Can you?
Input
The first line contains an integer T (1 ≤ T ≤ 10^4) specifying the number of test cases.
Each test case consists of a single line containing two integers a and b ( - 10^9 ≤ a, b ≤ 10^9, a ≠ 0, b ≠ 0), as described in the problem statement above.
Output
For each test case, print a single line containing the multiplication expression of a and b as a summation or subtraction of multiplication of special numbers. All special numbers must be between - 10^9 and 10^9 (inclusive). If there are multiple solutions, print any of them. It is guaranteed that an answer always exists for the given input.
The multiplication expression must be printed in exactly one line. A single term must be printed as in which z and w are both special numbers, # represents a single space, and x represents the multiplication operation. Two consecutive terms must be printed as in which z and w are both special numbers, # represents a single space, represents the multiplication operation, and represents either the addition operation + or the subtraction operation - . (Check the sample output for more clarification).
Example
Input
2
55 20
70 17
Output
60 x 20 - 5 x 20
-3 x 70 + 70 x 20
特殊数:最高位非零,其他位都是0 (1~9也算,0不算)
注意 <mark>pow函数返回值是浮点数</mark>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
char a[15],b[15];
int pa[15],pb[15];
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s%s",a+1,b+1);
int la=strlen(a+1);
int lb=strlen(b+1);
int fa=(a[1]=='-'?-1:1);//记录是正数还是负数
int fb=(b[1]=='-'?-1:1);
int ta=0,tb=0;
for(int i=(fa==1?1:2);i<=la;i++)
if(a[i]!='0') pa[++ta]=i;//记录非0数的位置
for(int i=(fb==1?1:2);i<=lb;i++)
if(b[i]!='0') pb[++tb]=i;
int f=fa*fb;//结果是正数还是负数
for(int i=1;i<=ta;i++){
for(int j=1;j<=tb;j++){
if(i==1&&j==1){
if(f==1) printf("%.f x %.f",(a[pa[i]]-'0')*pow(10,la-pa[i]),(b[pb[j]]-'0')*pow(10,lb-pb[j]));
else printf("-%.f x %.f",(a[pa[i]]-'0')*pow(10,la-pa[i]),(b[pb[j]]-'0')*pow(10,lb-pb[j]));
}
else
printf(" %c %.f x %.f",f==1?'+':'-',(a[pa[i]]-'0')*pow(10,la-pa[i]),(b[pb[j]]-'0')*pow(10,lb-pb[j]));
}
}
printf("\n");
}
return 0;
}