1005 -- 构造表达式

这是一个编程问题,要求使用加减乘除运算符从给定的三个整数组中构造表达式,使得前两个数的计算结果等于第三个数。如果可能,输出表达式,否则输出None。题目来源于某次编程竞赛。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

构造表达式

Time Limit:1000MS  Memory Limit:32768K
Total Submit:296 Accepted:197

Description

有一些三个整数构成的整数群,它的结构是:第一行整数N表示后面有N个几个整数群,每个整数群由三个整数组成。尝试用+、-、×、/(整除)来凑前两个数的计算结果,以图与第三个整数相等。如果能凑到相等,则输出该表达式,否则,输出None。输入将保证若表达式存在,则一定唯一。

Input

Output

Sample Input

5
123 1234 10
12 34 22
12 12 24
5678910 7 56789
9 4 2

Sample Output

1234/123=10
34-12=22
12+12=24
None
9/4=2

Source

ahstu@ICPC03

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace AK1005 {
        class Program {
            static void Main(string[] args) {
                int n = int.Parse(Console.ReadLine());
                while (n-- > 0) {
                    string[] sb = Console.ReadLine().Split();
                    int a = int.Parse(sb[0]), b = int.Parse(sb[1]), c = int.Parse(sb[2]);
                    int min = a;
                    int max = a;
                    if (b < min) min = b;
                    if (b > max) max = b;
                    if (max / min == c)
                        Console.WriteLine("{0}/{1}={2}", max, min, c);
                    else if (max - min == c)
                        Console.WriteLine("{0}-{1}={2}", max, min, c);
                    else if (max + min == c)
                        Console.WriteLine("{0}+{1}={2}", max, min, c);
                    else if (max * min == c)
                        Console.WriteLine("{0}*{1}={2}", max, min, c);
                    else
                        Console.WriteLine("None");
                }
            }
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值