2689Chinese Suit Tiles

2689   Chinese Suit Tiles

题目描述

Chinese suit tiles is one of traditional Chinese Dicegame, its origins can be traced back to before the Han Dynasty, according to legend, Chinese suit tiles and Chinese chess  belong to the same pulse, condensed the essence of ancient Chinese civilization, is also a quintessence of Chinese culture. China plates spread widely, basically covering most parts of China. Chinese suit tiles and Chinese mahjong card games are played similar, but more than mahjong skills and flexibility. Two to four people can play against, to hone and improve the analytical skills of thinking is very useful. Chinese suit tiles contains twenty kinds of cards , such  as "一,二,三,四,五,六,七,八,九,十,壹,贰,叁,肆,伍,陆,柒,捌,玖,拾" , each kind has four cards.  The rules of Chinese suit tiles is relatively simple , but more flexible. Tom has special hobby in Chinese suit tiles. As this kind game is very flexible, Tom is very difficult to see if he is the winner. As a very clever programmer, can you help him.

Each one has n (0 < n 21) cards, these cards must divide into some group, each group must have three cards, and each group must satisfy one of following rules:

1.      The value of each cards is equal, for example: the value of  "" is equal to "".

2.      The value of each cards is consecutive numbers, and each cards must  be lowercase Chinese character digital or capital Chinese character digital. For example:"一二三" is satisfied the condition, but "一贰三" is not satisfied the condition.

If the number of a kind card is equal to or more than three, they must in the same group. (So "一一一一二三" or "一二三一一壹" is not satisfied the condition )

Whoes cards satisfy the rules, he is the winner.

输入格式:

The first line contain a number n (0 n 21),the number of cards. If input 0 is the end of the case.

The following line contain a string of letters.

"a,b,c,d,e,f,g,h,i,j,A,B,C,D,E,F,G,H,I,J" is in place of "一,二,三,四,五,六,七,八,九,十,壹,贰,叁,肆,伍,陆,柒,捌,玖,拾".

输出格式:

If the cards satisfy the rules, output “Yes”.

If the cards don’t satisfy the rules, output “No”.

输入样例 复制
3
acb
3
aBc
3
aaA
6
aaaAbc
0
输出样例 复制
Yes
No
Yes
No

说明

1
1
通过提交
时空限制1000ms/128mb
题目来源2010湖大校赛
评测方式在线评测
题目类型
难        度