Generation

generate functionFri, 20 Jan 2023

You have decided to implement a program that shuffles N cards. Each of the N cards contains one integer from 1 to N, without duplicates. Initially, the card with integer i (1 ≤ i ≤ N) is the i-th card from the top. That is, the card with 1 is at the top, the card with 2 is second from the top, ..., the card with N is at the bottom, and so on. N) are placed at the bottom of the stack. This time, the cards are shuffled in the following way The stacked cards are divided into sets of M cards from the top. However, if the bottom set has less than M cards, it remains less than M. The cards are divided into sets of M cards from the top. The cards are rearranged so that the i-th set from the top (1 ≤ i ≤ M) is the i-th set from the bottom. That is, after separating them into their respective sets, the top set is the bottom, the second set from the top is the second from the bottom, ..., and so on. The second set from the top is the second from the bottom, ..., and the bottom set is the top. This operation is called a single shuffle. To shuffle again, repeat the same operation from the previous shuffled state. Output the order of the cards after shuffling K times. Input example 1 is shown below. Since N = 9, there are 9 cards. M = 3, so the cards are divided into sets of 3 cards each. Rearrange each set in the manner described above. This time, K = 1, so the shuffling is complete. Input values Input is given in the following format N M K The number of cards is given as an integer N, the number of cards per set as an integer M, and the number of shuffles as an integer K, in this order, separated by spaces. The input is on a single line, with a single newline at the end. Expected output Output the cards after shuffling K times in the following format, from top to bottom c_1 c_2 .... c_N The expected output consists of N lines. Each i-th line (1 ≤ i ≤ N) should contain c_i, the number of the i-th card from the top after shuffling. All output must be integers. The last line of output must end with a newline and must not contain any extra characters or blank lines.

#include<stdio.h> main() { int a1,a2,a3,a4,a5,a6,a7,a8,a9,n,m,k; scanf("%d %d %d",&n,&m,&k); a1=1; a2=2; a3=3; a4=4; a5=5; a6=6; a7=7; a8=8; a9=9; while(k) { k--; if(m==1) { a1=6; a2=3; a3=9; a4=5; a5=1; a6=7; a7=4; a8=8; a9=2; } if(m==2) { a1=8; a2=1;

Questions about programming?Chat with your personal AI assistant