2018 ACM ICPC Arabella Collegiate Programming Contest A

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 ≤ 104) specifying the number of test cases.

Each test case consists of a single line containing two integers a and b ( - 109 ≤ a, b ≤ 109, 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  - 109 and 109 (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

起初我们要选择一种输出方式

我选择的是(s1-s2)*(s3-s4)=s1*s2+s2*s4-s1*s4-s2*s3;

即我选择的是向上取,你也可以选择向下取,也可以一个向上一个向下

代码:

import java.util.Scanner;

public class Main {
    static int T,a,b;
    static int s1,s2,s3,s4;
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        T=sc.nextInt();
        while(T>0){
            a=sc.nextInt();
            b=sc.nextInt();
            s1=s2=s3=s4=0;
            
            if(a%10!=0){
                s1=(a/10+1)*10;//向上取后的值
                s2=10-a%10;//向上取后应减去的值
            }
            
            if(b%10!=0){
                s3=(b/10+1)*10;//向上取后的值
                s4=10-b%10;//向上取后应减去的值
            }
            
            if(s1==0&&s2==0&&s3==0&&s4==0){//如果都是特殊数直接输出
                System.out.println(a+" x "+b);
            }else if(s1==0&&s2==0){//第一个数是特殊的
                System.out.println(a+" x "+s3+" - "+a+" x "+s4);
            }else if(s3==0&&s4==0){//第二个数是特殊的
                System.out.println(s1+" x "+b+" - "+s2+" x "+b);
            }else{//都不是特殊的
                System.out.println(s1+" x "+s3+" + "+s2+" x "+s4+" - "+s1+" x "+s4+" - "+s2+" x "+s3);
            }
            
            T--;
        }
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值