Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 08-03-2005, 06:35 PM   #22
Unknown Hero
Home Sweet Abandonia

 
Join Date: Aug 2004
Location: Split, Croatia
Posts: 1,028
Default

2. Exam
Luka dislikes learning, but anyways, he will like to pass the most difficulty exam on the first year. During his last visit to university's canteen, he overheard that all students of second year know which questions will be in his exam. The truth is that no one actually knows it, but everyone thinks that someone else knows.
Luka now chooses person A from the second year and asks him what questions will be in the exam. Person A responds that he doesn't know, but that he thinks that person B knows. Then Luka asks the same question to person B, etc.
Write a program that will determine which student Luka should first ask about the exam, so that the number of questioned students is the biggest possible.

Entering parameters:
In the first line there is a whole number N, 2<=N<=1000, the number of students. Students are marked with numbers from 1 to N.
In every of next N lines there is one number. First number determines ordinal number of student that first student will send Luka to ask him about the exam, second number determines ordinal number of student that second student will send Luka to ask him about Exams, and so on.

Exiting parameters:
In first and only line write an ordinal number of student that Luka have to ask first about the exam, so that the number of students that he will meet on that way could be the biggest possible.
If there are more these students, then write a number of that student that has the smallest ordinal number.

Test examples:
exam.in
3
3
3
1
exam.out
2

exam.in
4
2
3
4
1
exam.out
1

exam.in
6
2
3
4
3
1
1
exam.out
5




Two more to go. I will post those two after at least one of members tries to solve one or both of previous two exams. k:
Unknown Hero is offline                         Send a private message to Unknown Hero
Reply With Quote
 


Similar Threads
Thread Thread Starter Forum Replies Last Post
Discussion Of Exams Kon-Tiki Programming 8 30-03-2007 07:27 PM
How Often Do You Cheat On Exams / Tests nace Blah, blah, blah... 40 16-10-2006 07:57 PM
Solution To Exams Kon-Tiki Programming 0 08-08-2005 05:37 PM
Exams Unknown Hero Programming 0 12-04-2005 08:40 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 07:25 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.