Programming Exercise 3

Source: Internet
Author: User

CSDN hero program competition
QUESTION Report game (2)
Address http://hero.csdn.net/
Code mounting gpl


Question details
There are N people (numbers 1-N) standing in a row to play the report game. The reporting process may take many rounds, with the following rules:
(1) If there are no more than three people remaining, the game will end.
(2) report the number of people, and then leave the odd number of people to continue the game, or leave the even number of people to continue the game.
Repeat the two steps (1) (2) until the end of the game.
Q: What are the cases of the remaining three groups? (Note: it is a three-person group. For example, if there are two or one remaining persons, they are not included in the result ).
Input n, (0 Output the final result.

# Include

 
  
Int how (int x) {static int a; // number of group 3 if (x> 3) // when the number of group members is greater than 3, take the child column {if (x % 2 = 0) // when the number of people is an even number {howmany (x/2); // obtain the odd howmany (x/2 ); // obtain the even number} else // when the number of students is odd book {howmany (x/2 + 1); // obtain the odd number of howmany (x/2 ); // obtain the even number} else if (x = 3) // when the number of three persons is 3, the number of three persons increases by 1 a ++; return ;} // start prompt: the start unique identifier of the Automatic Marking. Do not delete or add it. Int main (void) {printf ("% d", howmany (7); return 0;} // end // prompt: the unique identifier of Automatic Marking, do not delete or add.

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.