在for循环中更改字符 [英] Changing chars in for loop

查看:148
本文介绍了在for循环中更改字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个练习。 
John找到大机器,在那台机器上我有一个品尝者和监视器当我点击一次我得到B在监视器上,点击两次我得到BA,然后点击BAB,然后点击BABBA ...
OK in c ++我必须输入品尝者的数量(品尝者< = 40)。
这将是品尝点击次数。
1.B
2.BA
3.BAB
4.BABBA
5.BABBABAB
6.BABBABABBABBA
...
ALL B 更改为 BA .ALL A 更改为 B 。最后我必须计算A和B的数量。它必须扫描所有行的字符并再次更改再次或我输入多少品尝者我希望你明白了





我尝试过:



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

解决方案

同样的问题,同样的答案。



阅读本文,它将帮助您理解问题。

L系统 - 维基百科 [ ^ ]

引用:

我为while或fop循环尝试了很多代码但是它没有用



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

引用:

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



当你学习编程时,避免使用C和C ++语言,因为它们会使任何事情变得更复杂,因为程序员必须处理内存分配,数组大小调整等所有细节...... br />
选择能够处理所有这些细节的托管语言,以便您可以专注于编程问题。管理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 [ ^ ]



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

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



[更新]

引用:

不,我正在努力做到这一点,因为我准备在6月份进行竞争而且我已经很难过了10万次,但是我只是坚持并且我希望你们将帮助我



您应该能够用一张纸和一支钢笔进行锻炼,看看如何进行下一次迭代,您的程序将遵循相同的程序。

公理是:B

规则是:A=> B和B=> BA

下一次迭代:对于公理中的每个字母,应用匹配规则。


我们不做你的功课:设置是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!

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

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



如果你遇到一个特定的问题,那么请问一下,我们会尽力帮助。但我们不打算为你做这一切!


I have one exersise.
John find big machine and on that machine i got one taster and monitor when i click once i get B on monitor,Click twice i get BA,next click BAB,next click BABBA...
OK in c++ i have to input number of tasters (tasters<=40).
this will be number of taster clicks.
1.B
2.BA
3.BAB
4.BABBA
5.BABBABAB
6.BABBABABBABBA
...
ALL B CHANGE TO BA.ALL A CHANGE TO B.At the end i have to count how much A and B i have .It has to scan all row of chars and change all again again or how much tasters i input i hope you understand



What I have tried:

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

解决方案

Same question, same answer.

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.

[Update]

Quote:

no I AM TRYING TO DO THAT BECAUSE I AM PREPARING FOR COMPETITION IN JUNE AND I DID HARD EXERSISES 100000 TIMES HARDER THAT THIS BUT I JUST STUCK AND I HOPE U WILL HELP ME


You should be able to do the exercise with a sheet of paper and a pen, see how you do to go to next iteration, your program will follow the same procedure.
Axiom is: "B"
Rules are: "A" => "B" and "B" => "BA"
Next iteration: for each letter in axiom, apply the matching rule.


We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
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.

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


这篇关于在for循环中更改字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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