C language-Fox and rabbit stories, C language Fox

Source: Internet
Author: User

C language-Fox and rabbit stories, C language Fox

Description

There are 10 holes on the top of the mountain. One fox and one rabbit each have one hole. The fox always wants to eat rabbits. One day, the rabbit said to the fox, "if you want to eat, I have a condition. First, set the hole from 1 ~ 10. You should start from the 10th hole and go to the 1th hole to find me. The second time, the second time, in the future, there will be no limit on the number of such pushes. If you can find me, you can have a full meal. But I can't stop until I find it ." The fox started searching with a mouthful of promises. It found N holes from morning till night and was so tired that no rabbit was found. Which hole does the fox faint in? Which holes may my child be hiding in?

Input

Enter a positive integer N (1 <=n <= 1000)

Output

Line 1: Numbers of holes that rabbits can hide
Row 2: the number of the hole where the fox fell down

Sample Input
3
Sample output
2 4 5 7 8 9 10
6

 

1/* 2 variable definition: 3 n: A total of n holes, 4 k: the number of holes found at k (1 <= k <= n) 5 6 find_rabbit: returns the number of holes found at k. 7 8 */9 # include <stdio. h> 10 int find_rabbit (int k) {11 if (k = 1) {12 return 1; /* First time in hole 1 */13} else {14 if (find_rabbit (k-1) + k) % 10 = 0) {15 return 10; 16} else {17 return (find_rabbit (k-1) + k) % 10; 18} 19} 20} 21 void main () {22 int I, holes [10]; 23 int n = 24; 24 for (I = 0; I <10; I ++) {25 holes [I] = 1; /* initialized to represents the hole that the fox has not visited */26} 27 28 for (I = 1; I <= n; I ++) {29 holes [find_rabbit (I) -1] = 0;/* eg: The first time in the No. 1 hole, that is, holes [0] is set to 0, use index minus 1 and 0 to represent the hole x/30} 31 32 for (I = 0; I <10; I ++) {33 if (holes [I] = 1) {34 printf ("% d", I + 1);/* Because I starts from 0, so add 1 */35} 36} 37 printf ("\ n % d \ n", find_rabbit (n); 38 39 40}

 

Related Article

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.