如何反转数组中的数字 [英] How can I reverse the number in an array

查看:154
本文介绍了如何反转数组中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像我有3个数组,在第一个数组中,我有2个,我有2个,在第3个我有3个,我想将每个数组中的值复制到另一个数组,但在第一个元素中数组它应该有3个,在第2个2和第3个1



我尝试过:



i完成了问题的第一部分,要求用户输入数组中元素的数量,并再次要求他输入数组中每个元素的数字

解决方案

从一张纸和一支钢笔或一支铅笔开始。将每个数组绘制为一组框,并在正确的位置添加数字。现在看看在逻辑步骤中需要做些什么才能从那里得到答案。在弄清楚时记下每一步,随时更新图表。完成后,您只需要将您编写的伪代码转换为您计划用于程序的任何语言。


拿一张纸和3个代币。

画3个方格,每个方格放1个标记。

这是你的起点

你要做的是旋转

取1个标记,将其移出正方形

现在1平方为空,你可以从另一个方格移动1个标记,重复

最后,将标记移到一边在自由广场。



这是你的程序的工作方式,简单地说'旁白'是另一个变量。


like i have 3 arrays and in the 1st array i have 1 in the 2nd i have 2 and in the 3rd i have 3 and i want to copy the values in each array into another array but in the 1st element in the 1st array it should have 3 and in the 2nd 2 and in the 3rd 1

What I have tried:

i have finished the 1st part of the question which is asking the user to enter the number of the elements in the array and asking him again to enter the numbers in each element in the array

解决方案

Start with a piece of paper and a pen or pencil. Draw each array as a set of boxes, and add the numbers in the right places. Now see what needs to be done to get from there to the answer, in logical steps. Write each step as you figure it out, updating the diagrams as you go. When you have finished you just need to convert the pseudocode you have written into whatever language you plan to use for your program.


Take a piece of paper and 3 tokens.
Draw 3 squares, put 1 token in each square.
this is your starting point
What you want to do is a rotation
Take 1 token, move it outside of the squares
Now 1 square is empty, you can move 1 token from another square, repeat
And finally, move the token aside in the free square.

this is how your program will work, simply the 'aside' thing is another variable.


这篇关于如何反转数组中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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