题目:有十三张牌, 将最上面的抽出来放在最下面,之后将最上面的牌抽走, 若抽走的顺序是1 2 3 4 5 6 7 8 9 10 11 12 13 问原始的顺序是什么? (编程求出, 不许用链表实现)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int GetSequence(int* a, int* b)
{
int* tmp=NULL;
int j=0;
int* c[13] = {0};
if(NULL == a || NULL == b)
{
return -1;
}
for(int i=0; i<13; i++)
{
c[i]=b+i;
}
for(i=0; i<13; i++)
{
if(i==11)
{
*(c[1])=a[i];
continue;
}
else if(i == 12)
{
*(c[0])=a[i];
continue;
}
tmp=c[0];
*(c[1])=a[i];
for(j=0; j<13-i-1; j++)
{
c[j]=c[j+2];
}
c[--j]=tmp;
}
return 0;
}
void main()
{
int a[13] = {0};
int b[13] = {0};
for(int i=0; i<13; i++)
{
a[i] = i+1;
}
GetSequence(a,b);
for(i=0; i<13; i++)
{
printf("%d ", b[i]);
}
printf("\n");
}