HDU 1800

代码wa了。先放着等以后找问题
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
struct Node {
	int num;
	Node *Lu[10];
	Node() {
		num = 0;
		for (int i = 0; i < 10; i++)
			Lu[i] = NULL;
	}
};
int n;
Node *root = new Node;
Node *current, *newnode;
int insert(char *str) {
	int m;
	current = root;
	for (int i = 0; i < strlen(str); i++) {
		m = str[i] - '0';
		if (current->Lu[m] != NULL) {
			current = current->Lu[m];
			if (i == strlen(str) - 1) {
				++(current->num);
				n = current->num;
				return n;
			}
		}
		else {
			newnode = new Node;
			current->Lu[m] = newnode;
			if (i == strlen(str) - 1) {
				++(current->Lu[m]->num);
				n = current->Lu[m]->num;
				return n;
			}
			current = newnode;
		}
	}
}
int main() {
	int Max, T;
	string Yi;
	char Zheng[31];
	while (cin >> T) {
		if (T == 0) {
			cout << 1 << endl;
			continue;
		}
		Max = 0;
		n = 0;
		for (int i = 0; i < T; i++) {
			memset(Zheng, 0, sizeof(Zheng));
			cin >> Yi;
			int j, q = 0;
			for (j = 0; j < Yi.length(); j++) {
				if (Yi[j] != '0')
					break;
			}
			for (int k = j; k < Yi.length(); k++)
				Zheng[q++] = Yi[k];
			Max = max(Max, insert(Zheng));
		}
		cout << Max << endl;
		delete root;
		root = new Node;
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值