プロが教える店舗&オフィスのセキュリティ対策術

JAVA プログラミング ロッカーパズル
授業で英語のJAVAプログラミングをやってます。アメリカではそこそこ有名なゲームらしいのですがまったく意味がわかりません。もし、英語のわかる方、プログラミングのできる方いましたら、回答お願いします。JAVAの配列のチャプターなので配列を使ってお願いします。以下問題です。

A school has 100 lockers and 100 students. All lockers are closed on the first day of shcool. As the students enter, the first student, denoted S1, opens every locker. Then the second student, S2, begins with the second locker, denoted L2, and closes every other locker. Student S3 begins with the third locker and changes every third locker (closes it if it was open, and opens it if it is closed). Student S4 begins with locker L4 and changes every fourth locker. Student S5 starts with L5 and changes every fifth locker, and so on, until student S100 changes L100.

After all the students have passed through the building and changed the lockers, which lockers are open? Write a java program to find your answer.

Hint: Use an array of 100 boolean elements, each of which indicates whether a locker is open (true) or closed (false). Initially, all lockers are closed.

A 回答 (1件)

http://ideone.com/0K1UW

まぁ算数的によく考えたらそりゃ10になるわなぁ。
#どうせなら問題文がL1からじゃなくてL0にしてくれたら良かったのに(汗)
    • good
    • 0
この回答へのお礼

お礼遅れてすいません。
ゆっくり考えたら確かに10ですね~
一瞬全然わからなくて焦ってたので
とても助かりました。
ありがとうございます!

お礼日時:2010/10/26 13:26

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!