Evergreen ACM 13-Perimeter report (Jun haijun), acm13-

Source: Internet
Author: User

Evergreen ACM 13-Perimeter report (Jun haijun), acm13-

1/* 2 // subject title: 3 * circle reports () 4 5 // subject description: 6 * There is a circle of n (n <= 100, sequence Number (from 1 to n ). Start reporting data from the first person (report data from 1 to m (m <= 9). Anyone who reports data to m will leave the circle and ask the person who left the first number? 7 8 // input Description: 9 * the input is two positive integers, the first <= 100, the second <= 9; 10 11 // output description: 12 * the output is a positive integer; 13 14 // style input: 15 100 316 17 // style output: 18 9119 20 // solution thinking: 21 1. Define a length of 100 array a and initialize it to 0; 22 2. The input values of the receiving keyboard are n, m, and the first n-1 elements of array a are assigned a value of 1 ~ N; 23 3. Establish a two-layer nested loop. The outer loop ends until the number of exit persons is n-1. The inner loop loops from 0 to n, and the non-zero data in array a is set to m, at the same time, the number of exit persons is recorded. 24. After the loop ends, the non-zero element value of the last a array is output. 25 */26 27 # include <stdio. h> 28 29 int main () 30 {31 int I, n, m, k = 0, cnt = 0, a [100] = {0 }; 32 scanf ("% d,", & n, & m); 33 for (I = 0; I <n; ++ I) 34 {a [I] = I + 1;} 35 while (cnt <n) 36 {37 for (I = 0; I <n; ++ I) 38 if (a [I]! = 0) 39 {40 k ++; 41 if (k = m) {a [I] = 0; k = 0; cnt ++ ;} 42} 43 if (cnt = N-1) break; 44 else I = 0; 45} 46 for (I = n-1; I> = 0; -- I) 47 if (a [I]! = 0) printf ("% d", a [I]); 48 return 0; 49}

 

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.