自定义“Very Long Int”分部问题
因此,对于一个非常愚蠢的 C++ 项目,我们正在制作自己的长整型类,称为 VLI(Very Long Int)。它的工作方式(他们支持它,责怪他们愚蠢)是这样的:
- 用户输入最多 50 位数字,这些数字作为字符串输入。
- 字符串存储在预先创建的 Sequence 类中,该类将字符串按相反顺序存储在数组中。
这意味着,当输入“1234”时,它将存储为[4|3|2|1]。
所以,我的问题是:如何仅使用这些字符数组进行除法?
如果输入的答案超过 32 位,我就不能使用整数来检查内容,而且他们基本上说在这里使用长整数是作弊。
欢迎任何意见,如果需要的话我可以提供更多说明,谢谢大家。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实现你在小学学到的长除法算法。
首先实施减法。创建一个可以从输入中减去任何数字的函数。然后你应该能够检测结果是否为阴性。修改此函数以允许在减法之前对数字进行字符串移位...
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…
把你的学校数学书拿出来,我想你几年前在学校做过手工除法。原理完全一样:)
Get your school math book out, you did manual division some years ago in school I suppose. It is exactly the same principle :)
土豆泥说得对。我过去编写了一个 Pascal 程序,它可以将任意长度的数字作为字符串处理,并且它也可以计算平方根。
这里提醒一下长除法的技巧:长除法到小数位
Potatoswatter is correct. I wrote a Pascal program in the past that worked on arbitrary length numbers as strings, and it could calculate the square root as well.
Here is a reminder of technique for long division: Long Division to Decimal Places