在一个列表中添加值并使用其他列表中的值减去它

时间:2017-06-12 09:28:35

标签: java excel apache

  1. 我有一张excel表,我可以从中访问数据并使用java进行验证
  2. 到目前为止问题是,excel有一列有200多行,正负值就像EXCEL IMAGE
  3. 我试图写代码,我可以删除行值,可以用负值减去行值。
  4. 这里的问题是,如果查看excel表,必须添加值2,3,5以便减去-8 所以我得到零。
  5. 如果我们假设值为1,2,2,3和-8
  6. ,我不知道如何添加这些值三个值甚至更多值
  7. 到目前为止,我能够实现下面的功能,它添加了两个值并在肯定列表中然后减去 它在否定列表中具有匹配的负值,并给出最终结果为零。
  8. 所以我的要求是让我知道在有两个以上的值可以添加的情况下如何实现类似的功能
  9. 希望你能帮忙!谢谢!
  10. 这里是伪代码。

    1)一个负数列表并排序

    2)一个postivie数字列表并排序

    3)迭代并以负列表中的最大数字开始

    4)检查肯定列表中等号或小号的索引

    5)使用此索引迭代肯定列表:

     a) if current positive number 
        1) equal to negative number - nullify and put them in map, go to next negative number
        2) else if less than negative number - 
        i) get the difference of this positive number and the negative number 
        ii) create a variable for this difference and put it in while loop
        iii) search for the index of the number equal to or lesser to this difference.
        iv) get the second positive number and if is 
            a) equal to difference, nullify all by updatng index of the negative and two positives numbers as NA
                   update difference to 0 and exit while and go to next negative number
            b) else if the second positive number is less than the difference, sum the two numbers and negative number
               and get the difference and update the difference variable with this new value and iterate while loop
            c) if there is no lesser or mathcing number equal to difference, 
               come out of while and pick the next element in positive list as done in step (v) and get next number
               and repeat further.
    

    看看你现在能不能帮助我......

0 个答案:

没有答案