无法弄清楚如何做这个练习 [英] Can't figure out how to do this exercise

查看:73
本文介绍了无法弄清楚如何做这个练习的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我无法弄清楚如何做这个程序,你们中的任何一个都可以伸出援助之手吗?



邮差帕特感到无聊了一晚邮政分拣办公室打破了夜班的单调,他在邮局进行了一系列邮箱(全部最初关闭)的实验。这些邮箱编号为1到150,从邮箱2开始,他打开所有偶数邮箱的门。接下来,从邮箱3开始,他去了每三个邮箱,如果它关闭则打开它的门,如果它打开则关闭它。然后他每四个门重复一次这个程序,然后每隔五个门,依此类推。当他完成时,他对封闭邮箱的分发感到惊讶。写一个程序来确定和显示这些邮箱(即在过程结束时关闭了哪些门)。

Hey i can't figure out how to do this program, would any of ye could give a hand?

"Postman Pat became bored one night at the postal sorting office and to break the monotony of the nightshift, he carried out the following experiment with a row of mailboxes (all initially closed) in the post office. These mailboxes are numbered 1 through to 150, and beginning with mailbox 2, he opened the doors of all the even-numbered mailboxes. Next, beginning with mailbox 3, he went to every third mailbox, opening its door if it was closed and closing it if it was open. Then he repeated this procedure with every fourth door, then every fifth door, and so on. When he finished, he was surprised at the distribution of closed mailboxes. Write a program to determine and display which mailboxes these were (i.e. which doors were closed at the end of the process)."

推荐答案

首先考虑如何手动完成:然后模拟e进程。

创建一个数组来保存邮箱,并为每个邮箱分配一个关闭的值。

然后循环切换将邮箱从打开切换到关闭。

正如你所知,你需要的只是两个嵌套循环...



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



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但是我们不会为你做这一切!
Start by thinking how you would do it manually: and then emulate the process.
Create an array to hold the mailboxes, and assign each a value that says "closed".
Then loop through toggling the mailboxes from open to closed appropriately.
As you have been told, all you need is two nested loops...

Try it yourself, you may find it is not as difficult as you think!

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!


我们不做你的功课:它会让你思考你在学校学到的东西。



提示:

拿一张纸,用手工做,只有20个邮箱(仅用于测试)。

您的程序必须这样做。

完成偶数框后,显示框状态以查看它是否与您的纸张相符。完成第三个框后,显示框状态以查看它是否与您的纸张相符。等等。



如果您的程序出现问题,请使用调试器逐步查看代码,检查变量,直到您了解它出错的地方为止。为什么。



如果您遇到困难,请告诉您的老师,这将有助于他发现您的弱点并予以纠正。
We do not do your homework: it is set to make you think about what you have learned at school.

Hint:
Take a sheet of paper and do by hand what is said with only 20 mailboxes (it is only for testing).
Your program will have to do the same.
When the even boxes are done, display the boxes status to see if it match your paper sheet. When the third boxes are done, display the boxes status to see if it match your paper sheet. and so on.

If you have problems in your program, use the debugger to see your code execute step by step, inspect variables until you understand where it goes wrong and why.

If you are stuck, Tell your teacher it will help him to spot your weakness and correct it.


这篇关于无法弄清楚如何做这个练习的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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