如何扫描数组和更改元素 [英] How to scan array and change elements

查看:110
本文介绍了如何扫描数组和更改元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在c ++中,我必须制作这样的程序。

输入t数.T数是点击次数的点击次数。

点击一下我必须得到B程序。我将显示你的完整地图。

1,2,3 ..是t变量的数量

1.B

2.BA

3.BAB

4.BABBA

5.BABBABAB

...

所有B更改为BA

所有A更改为B.

For循环必须扫描此字符数组t(变量)时间和每次将B更改为BA和A更改为B.

t(变量)< = 40

帮助我。



我尝试了什么:



我为while或fop循环尝试了很多代码,但它没有工作

解决方案

正如你所知,独自学习是一种不好的做法。选择三种语言中的一种 - 或者如果你是一个初学者,暂时抛弃这个地段并从C#开始 - 并获得一本书或一门课程并从头到尾跟随它。

抓取随机作业并试图在没有书籍或课程所涉及的结构的情况下进行这些作业并不能教会你什么,除了挫折和不良行为。



请坐下来,考虑如何手动处理任务,并尝试在纸上计算出算法。然后考虑如何实现该算法!

这并不复杂:它只是一个生成每一代的循环,其中有一个循环来处理最后一个字符串并生成新的。首先编写一个以字符串作为参数的函数,按照说明处理它并返回带有结果的新字符串。然后你可以根据需要多次调用它来生成新的新一代。


阅读本文,它将帮助你理解这个问题。

L-system - Wikipedia [ ^ ]

Quote:

我已经为while或fop循环尝试了很多代码,但是它没有工作



我们为代码中的特定问题提供帮助:显示代码并说明问题。 />

引用:

在c ++中,我必须制作这样的程序。



在学习编程时,避免使用C和C ++语言,因为它们会使任何事情变得更复杂,因为程序员必须处理内存分配,数组大小调整等每一个细节......

选择一种可以处理所有这些的托管语言细节,以便你c专注于你的编程问题。管理C#,Java,Visual Basic等。

找一个教程并按照课程。



一旦你选择了一门语言,学习它的调试器,它是一个宝贵的工具,可以帮助你了解哪些代码做了什么。



当你不明白你的代码在做什么或为什么它做什么确实如此,答案是调试器

使用调试器查看代码正在做什么。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]



http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first- java-application.html [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有找到错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


参见 C教程 - 学习C - Cprogramming.com [ ^ ]。

Hi,
In c++ i have to make program like this.
Input t number.T number is number of taster clicks.
One click i have to get B on program.I will show u full map.
1,2,3.. are number of t variable
1.B
2.BA
3.BAB
4.BABBA
5.BABBABAB
...
All B changes to BA
All A changes to B.
For loop have to scan this array of chars t(variable) times and every time to change B to BA and A to B.
t(variable)<=40
Help me.

What I have tried:

I have tried lot of codes for while or fop loop but it didn't work

解决方案

As you have been told, learning "on your own" is a bad way to do anything. Pick one of the three languages - or if you are a total beginner, dump the lot for the moment and start with C# - and get a book or a course and follow it from beginning to end.
Grabbing random assignments and trying to do them without the structure that a book or course involves doesn't teach you anything much, except frustration and bad practices.

So sit down, think about how you would process the task manually, and try to work out the algorithm on paper. Then think about how to implement that algorithm!
This isn't complex: It's just a loop to generate each generation, with a loop inside that to process the last string and generate the new. Start by writing a function which takes a string as a parameter, processes it as per the instructions and returns a new string with the results. Then you can work on calling that as many times as you need to generate new new generation.


Read this, it will help you to understand the problem.
L-system - Wikipedia[^]

Quote:

I have tried lot of codes for while or fop loop but it didn't work


We provide help for specific problems in your code: Show your code and state the problem.

Quote:

In c++ i have to make program like this.


As you learn programming, avoid C and C++ languages as they makes anything more complicated because the programmer have to handle every detail like memory allocation, array resize ...
Choose a managed language that will handle all those details, so that you can concentrate on your programming problems. C#, Java, Visual Basic and others are managed.
Find a tutorial and follow the course.

Once you have chosen a language, learn its debugger, it is an invaluable tool to help you learn which code does what.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


See C Tutorial - Learn C - Cprogramming.com[^].


这篇关于如何扫描数组和更改元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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