small help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 15
Reputation: look@me is an unknown quantity at this point 
Solved Threads: 0
look@me look@me is offline Offline
Newbie Poster

small help

 
0
  #1
Mar 22nd, 2008
i have a small problem in my ass and i dont know how to solve it


the problem is:

This problem is a game where n objects are arranged in a circle and every mth object is deleted until 1 object is left. The original problem is said to derive from a suicide pact among 41 rebels trapped by the Romans in the first century. The rebels decided to kill every third person until one is left and can escape in a boat that can take only one person. Josephus, the historian who lived to tell the story quickly figured out where he should position himself from the starting point in the circle so that he would survive.
Suppose you were in that situation with the only difference that you have your palm PC to quickly find out the lucky position to survive. Your program should be able to handle the following situation:
n people (n > 0 ) are initially arranged in a circle, facing inwards, and numbered from 1 to n. The numbering from 1 to n proceeds consecutively in a clockwise direction. Starting with person number 1, counting continues in a clockwise direction, until we get to person number k (k > 0), who is promptly killed. Counting then proceeds from the person to his immediate left, to kill the kth person, and so on, until only one person remains.
For example, when n = 5 and k = 2, the order of execution is 2, 4, 1, and 5. The survivor is 3.

Input
Input data is to be read from a file roulette.in. Each line in this file contains values for n and k (in that order). A line containing values of 0 for n and k will terminate input. Your program does know not the maximum number of people taking part in this tragic event.
Output
For each input line, output in a file roulette.out the position of the sole survivor.
Sample Input
1 1
1 5
8 3
0 0

Sample Output
1
1
7






my try i put it as a zip file
Attached Files
File Type: zip Problem4.zip (3.4 KB, 10 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,350
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: small help

 
0
  #2
Mar 22nd, 2008
Originally Posted by look@me View Post
i have a small problem in my ass and i dont know how to solve it
That's not very descriptive of the problem. You need to be a bit more specific about what you can not do or understand ?
Last edited by Ancient Dragon; Mar 22nd, 2008 at 5:50 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 15
Reputation: look@me is an unknown quantity at this point 
Solved Threads: 0
look@me look@me is offline Offline
Newbie Poster

Re: small help

 
0
  #3
Mar 24th, 2008
my problem is i cant output the right answer
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,810
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: small help

 
0
  #4
Mar 24th, 2008
Originally Posted by look@me View Post
my problem is i cant output the right answer
You don't know how to get input from the file? You don't know which algorithm to use to solve it mathematically? You don't know how to take your mathematical algorithm and turn it into a C++ function? You don't know how to call the function? You get the right answer, but you can't display it correctly? What?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC