1 #include2 #include 3 4 #define BOOLEAN int 5 #define TRUE 1 6 #define FALSE 0 7 8 #define MAX 52 9 #define INPUT_COUNT_EACH_LINE 26 10 11 typedef struct tagPile 12 { 13 char rank[MAX]; 14 char suit[MAX]; 15 int cardCount; 16 }Pile; 17 18 Pile pile[MAX] = { { 0}}; 19 int pileCount = 0; 20 21 char card[MAX][2] = { { 0}}; 22 23 BOOLEAN getNewPack() 24 { 25 int i = 0; 26 int j = 0; 27 int k = 0; 28 char line[100] = { 0}; 29 30 for(i = 0; i < 2; i++) 31 { 32 gets(line); 33 if(line[0] == '#') 34 { 35 return 0; 36 } 37 38 for(j=0; j 2) 67 { 68 if(compareCard(pileId, pileId-3)) 69 { 70 return pileId-3; 71 } 72 } 73 else if(pileId > 0) 74 { 75 if(compareCard(pileId, pileId-1)) 76 { 77 return pileId-1; 78 } 79 } 80 81 return pileId; 82 } 83 84 void moveCard(int pileIdNew, int pileIdOld) 85 { 86 int cardCountNew = pile[pileIdNew].cardCount; 87 int cardCountOld = pile[pileIdOld].cardCount; 88 cardCountNew++; 89 90 pile[pileIdNew].cardCount++; 91 pile[pileIdNew].rank[cardCountNew-1] = pile[pileIdOld].rank[cardCountOld-1]; 92 pile[pileIdNew].suit[cardCountNew-1] = pile[pileIdOld].suit[cardCountOld-1]; 93 pile[pileIdOld].cardCount--; 94 95 return; 96 } 97 98 void moveOnePile(int pileIdOld) 99 {100 memcpy(&pile[pileIdOld], &pile[pileIdOld+1], sizeof(Pile));101 102 return;103 }104 105 void moveAllPile(int pileIdOld)106 {107 for(; pileIdOld < pileCount-1; pileIdOld++)108 {109 moveOnePile(pileIdOld);110 }111 112 pileCount--;113 114 return;115 }116 117 118 void mergePile(int pileId)119 {120 int pileIdNew = 0;121 int pileIdOld = pileId; 122 123 for(pileIdNew = pileIdOld; pileIdNew 1)162 {163 printf("%d piles remaining:", pileCount); 164 }165 else{166 printf("%d pile remaining:", pileCount);167 }168 169 printf("%d piles remaining:", pileCount);170 for(i = 0; i < pileCount; i++)171 {172 printf(" %d", pile[i].cardCount);173 }174 printf("\n");175 }176 177 int main(int argc, char *argv[])178 {179 int i = 0;180 181 while(getNewPack())182 {183 for(i = 0; i < MAX; i++)184 {185 putCard(i); 186 mergePile(pileCount-1);187 }188 189 printCard();190 }191 192 return 0;193 }