Magician's guess Poker. Magic use a deck of cards in thirteen spades, stacked together in advance lined up after them are dealt face down. He told the audience: I do not see a license number only a few can guess what each card, I count out loud, you hear, do not believe? You see. The magician goes on top of the card number is 1, turned it over just spades A, the A of spades on the table, then top to bottom more than a few hands of cards, the second number 1, 2, the first card in this card Diego below, the second card is turned over, exactly 2 spades, it will also be on the table. The third number 1, 2, turn on the first two cards this card Diego below, the third card is turned over, exactly 3 spades. This in turn will turn out 13 cards full, accurate. Asked the magician card in the hands of the original order what arrangements?
** input format requirements: message: "Order of The Original of Cards IS:"
** Output format requirements: "% d"
run the example as follows:
of The Order of Original Cards IS: 2. 8. 1. 5 10. 4. 9. 11. 3 12 is 7613
#include<stdio.h>
int main()
{
int a[14]={0};
int i,n,j=1;
printf("The original order of cards is:");
for(i=1;i<=13;i++)
{
n=1;
do{
if(j>13) j=1;
if(a[j]) j++;
else{
if(n==i) a[j]=i;
j++;
n++;
}
}while(n<=i);
}
for(i=1;i<=13;i++)
printf("%d ",a[i]);
printf("\n");
}
Type:
topic of going round in circles.
Ideas:
- Think about, to find the law
- First time to a [0] assignment, the second a [1] is not assigned to a [2] Assignment
- +0+1+2+3…
- Each initialized to zero, the known sequence assignment.
- Array start counting from zero, the present entitled Reflection convenience, so removed a [0]
NOTE:
A [13 is] automatically initializes the global variables when
Mainly is this
. 1 2 3,456,789,101,112,131,234
. 1 1,212,312,341,234,512,345