定制“Very Long Int”分部问题 [英] Custom "Very Long Int" Division Issue

查看:104
本文介绍了定制“Very Long Int”分部问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,对于C ++中一个非常愚蠢的项目,我们正在创建我们自己的长整数类,称为VLI(Very Long Int)。它的工作方式(他们负责它,谴责他们的愚蠢)是这样的:


  1. 用户输入最多50位数,输入为字符串。

  2. 字符串存储在预先创建的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:

  1. User inputs up to 50 digits, which are input as string.
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆