Algorithm-skillfully row playing cards (c language) __ algorithm

Source: Internet
Author: User
*
Xiaoming just on primary school, learned the first poker "magic", everywhere to show people. The Magic's content is this:

    he holds a stack of cards in his hand: A, 2, ... J,q,k altogether 13. He first carefully designed their own order, and then face down and hold, to start the performance.

    He first took one from the bottom and put it on top, and take one from the bottom. Open the table, is a, and then from the bottom of the top, and then from the bottom of the open table, is 2;
	So circulate until the hand has only a card, turn open the table, just is K. At

    this time, the order of the table card is: a,2,3,4,5,6,7,8,9,10,j,q,k

    please calculate, Xiao Ming at the beginning of the hand in the order of the cards.

    write the results, comma split, xiaoming "Magic" at the beginning, the bottom of the card output as the first data.

* *
#include "stdio.h"
#include "string.h"
int main ()
{
	int i,index,temp;
	int a[13];
	memset (A,0,sizeof (a));   Initialization array is 0 for      
	(i=1,index=1;i<14;i++) {while
		(1) {
			if (a[index]==0) {
				a[index]=i;break
			} else index++;
		}		
		Temp=0;   
		while (1) {
			index++;
			index=index%13;
			if (a[index]==0)	temp++;
			if (temp==2 | | i==13) break;			
		}

	for (i=0;i<13;i++)
	{	if (a[i]<=10) printf ("%d", A[i]);
		else if (a[i]==11) printf ("J");
		else if (a[i]==12) printf ("Q");
		else printf ("K");
	}
	printf ("\ n");
	
	return 0;
}

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.