⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2353.cpp

📁 哈尔滨工业大学ACM 竞赛网上在线试题集锦的源代码
💻 CPP
字号:
/* This Code is Submitted by wywcgs for Problem 2353 on 2006-09-14 at 16:39:04 */
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 102400;
const int TN = 52;
const char CARD[] = "AJQK";
const char COL[] = "HDSC";
const char V[] = { 1, 11, 12, 13 };

class Trie {
public:
	int f;
	Trie *child[TN];
	Trie(int cf) : f(cf) { for(int i = 0; i < TN; i++) child[i] = NULL; }
	~Trie() { for(int i = 0; i < TN; i++) if(child[i] != NULL) delete child[i]; }
	int count() const;
	void insert(int*);
};
int Trie::count() const {
	int cnt = 1;
	for(int i = 0; i < TN; i++)
		if(child[i] != NULL) cnt += child[i]->count();
	return cnt;
}
void Trie::insert(int* c) {
	if(c[f] == -1) return;
	if(child[c[f]] == NULL) child[c[f]] = new Trie(f+1);
	child[c[f]]->insert(c);
}

int getCard();

int main()
{
	int card[N], pn;
	
	while(scanf("%d", &pn) != EOF && pn != 0) {
		Trie *root = new Trie(0);
		for(int i = 0; i < pn; i++) {
			int n; scanf("%d", &n);
			for(int j = 0; j < n; j++) card[n-1-j] = getCard();
			card[n] = -1;
			root->insert(card);
		}
		printf("%d\n", root->count()-1);
	}
	
	return 0;
}

int getCard()
{
	int c = -1, cc;
	scanf("%d", &c);
	if(c == -1) {
		char x; scanf("\n%c", &x);
		for(int i = 0; i < 4; i++)
			if(x == CARD[i]) { c = V[i]; break; }
	}
	char col = getchar();
	for(int i = 0; i < 4; i++)
		if(col == COL[i]) { cc = i; break; }
	return cc*13+c-1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -