定制“Very Long Int”分部问题 [英] Custom "Very Long Int" Division Issue
问题描述
- 用户输入最多50位数,输入为字符串。
- 字符串存储在预先创建的Sequence类中,以相反的顺序将该字符串存储在数组中。
这意味着,当输入1234时,它被存储为[4 | 3 | 2 | 1]。
问题是这个:我怎么只使用这些数组的chars进行除法?
如果输入答案超过32位数,我不能使用ints检查
任何输入都是欢迎的,如果需要,我可以给更多的澄清,谢谢大家。
实施你在小学学到的长分算法。
实现减法。创建一个函数,可以从输入中减去任何数字。然后你应该能够检测结果是否为负。修改此函数以允许数字在减去...之前进行字符串移位。
So, for a very silly project in C++, we are making our own long integer class, called VLI (Very Long Int). The way it works (they backboned it, blame them for stupidity) is this:
- User inputs up to 50 digits, which are input as string.
- String is stored in pre-made Sequence class, which stores the string in an array, in reverse order.
That means, when "1234" is input, it gets stored as [4|3|2|1].
So, my question is this: How can I go about doing division using only these arrays of chars?
If the input answer is over 32 digits, I can't use ints to check for stuff, and they basically saying using long ints here is cheating.
Any input is welcome, and I can give more clarification if need be, thanks everyone.
Implement the long division algorithm you learned in grade school.
Start by implementing subtraction. Create a function which can string-subtract any number from the input. Then you should be able to detect whether the result is negative. Modify this function to allow the number to be string-shifted before you subtract…
这篇关于定制“Very Long Int”分部问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!