首页 > 学院 > 开发设计 > 正文

HDU 1800

2019-11-08 01:23:36
字体:
来源:转载
供稿:网友
代码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;}
上一篇:C分配内存空间

下一篇:一笔画问题

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表