127 - Accordian Patience

You are to simulate the playing of games of``Accordian'' patience, the rules for which are as follows:

Deal cards one by one in a row from left toright, not overlapping. Whenever the card matches its immediate neighbour onthe left, or matches the third card to the left, it may bemoved onto that card. Cards match if they are of the same suit or same rank.After making a move, look to see if it has made additional moves possible. Onlythe top card of each pile may be moved at any given time. Gaps between pilesshould be closed up as soon as they appear by moving all piles on the right ofthe gap one position to the left. Deal out the whole pack, combining cardstowards the left whenever possible. The game is won if the pack is reduced to asingle pile.

Situations can arise where more than oneplay is possible. Where two cards may be moved, you should adopt the strategyof always moving the leftmost card possible. Where a card may be moved eitherone position to the left or three positions to the left, move it threepositions.

Input

Input data to the program specifies theorder in which cards are dealt from the pack. The input contains pairs oflines, each line containing 26 cards separated by single space characters. Thefinal line of the input file contains a # as its first character.Cards are represented as a two character code. The first character is theface-value (A=Ace, 2-9, T=10, J=Jack, Q=Queen, K=King) and the second characteris the suit (C=Clubs, D=Diamonds, H=Hearts, S=Spades).

Output

One line of output must be produced foreach pair of lines (that between them describe a pack of 52 cards) in theinput. Each line of output shows the number of cards in each of the pilesremaining after playing ``Accordian patience'' with the pack of cards as describedby the corresponding pairs of input lines.

SampleInput

QD AD 8H 5S 3H 5H TC 4D JH KS 6H 8S JS ACAS 8D 2H QS TS 3S AH 4H TH TD 3C 6S

8C 7D 4C 4S 7S 9H 7C 5D 2S KD 2D QH JD 6D9D JC 2C KH 3D QC 6C 9S KC 7H 9C 5C

AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AD2D 3D 4D 5D 6D 7D 8D TD 9D JD QD KD

AH 2H 3H 4H 5H 6H 7H 8H 9H KH 6S QH TH AS2S 3S 4S 5S JH 7S 8S 9S TS JS QS KS

#

SampleOutput

6 piles remaining: 40 8 1 1 1 1

1 pile remaining: 52

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值