表达式的构造输出的计算问题,运用C语言的程序的设计的方式实现

Problem Description
A toothpick expression uses toothpicks to represent a positive integer. The expression consists of operands and operators.

Each operand consists of one or more vertical toothpicks ("|"); the value of the operand is the number of toothpicks.

The operators that can appear in an expression are addition and multiplication. The addition operator is the plus sign ("+"), which consists of one vertical and one horizontal toothpick. The multiplication operator is the letter "x", which also consists of two toothpicks. Multiplication has precedence over addition.

The expression must begin with an operand. Thereafter, operators and operands alternate. Finally, the expression must end with an operand. Given a positive integer, your program must represent it as a toothpick expression, using the smallest number of toothpicks.

Input
The input file will consist of one or more lines; each line will contain data for one instance of the problem. More specifically, each line will contain one positive integer, not exceeding 5000.

Output
Each line of input will give rise to one line of output, consisting of: the number of toothpicks used in the expression, the expression, and the given integer from the input, formatted as shown in the sample output. The word "toothpicks" (even if the answer is 1) will be preceded by one blank space and followed by a colon and one blank space. An equal sign (but no blank spaces) will separate the expression from the given number. The expression should not contain any spaces.

If there are multiple expressions which use the smallest number of toothpicks, any such expression is acceptable.

Sample Input
35
37
53

Sample Output
14 toothpicks: |||||||x|||||=35
17 toothpicks: ||||||x||||||+|=37
21 toothpicks: |||||x|||||x||+|||=53

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!

相似问题

6
【C语言】表达式求值问题,应用“栈”编写一个计算器
5
在线等高手,怎么利用javascpt语言的eval函数,实现一个简单的表达式计算器,怎么做?
1
ball ball各位大佬,C语言中序表达式树求值问题
2
C语言写一算法,对输入的表达式中括号匹配情况检查。匹配的括号需要成对出现,且不嵌套。
0
c语言进行复杂表达式的计算
1
数据结构题目(c语言),把只能实现带小括号的表达式计算改为可以带小中大括号的表达式计算
1
表达式计算,利用符号运算的法则化简表达式,C语言的思路
0
表达式计算,求出相等的表达式构成的等式,采用C语言实现计算
1
表达式解析前缀表达式再计算表达式的值,这个用C语言来实现的方式?
0
一个有关于多项式表达式的计算的问题,多项式表达式求值用C语言做
0
怎么解决这个jasvascrpt表达式计算的问题
2
如何用正则表达式提取所有符合「介于两个特定字符串a和b之间」这一条件的内容?
0
一个表达式的优先级方面的计算的问题,算法问题采用C语言计算的方式是什么
0
运用RPN算法解决这个组合排列的表达式算法?基于C语言程序
0
前缀表达式的计算问题,单个符号,输出结果,使用C语言计算
0
路径距离计算保留2个小数的做法,运用C语言的表达方式
2
C语言数学表达式求大神解答
4
关于表达式 a<1&&--a>1 的运算优先级问题
0
用罗马数字构成的表达式的计算问题,怎么采用C语言程序的设计的思路来实现
0
表达式的转换和解析的问题,怎么利用C语言的算法的思维方式来实现的代码编写