HDU-1004 Let the Balloon Rise
来源:互联网 发布:公司名义开淘宝店 编辑:程序博客网 时间:2024/05/24 06:30
可以用map做,这里用的是Trie树
#include <cstdio>#include <iostream>#include <cstdlib>#include <string>using namespace std;typedef struct node { struct node* next[26]; int value; int num;} Node;Node* createTrie() { Node* root = ( Node* )malloc( sizeof( Node ) ); for( int i = 0; i < 26; i++ ) { root->next[i] = NULL; } root->value = root->num = 0; return root;}void insert( Node* root, string str ) { Node* r = root; for( int i = 0; i < str.size(); i++ ) { if( r->next[str[i] - 'a'] == NULL ) { Node* p = createTrie(); r->next[str[i] - 'a'] = p; } r = r->next[str[i] - 'a']; //r->num++; } r->num++; r->value = 1;}int find( Node* root, string str ) { Node* r = root; for( int i = 0; i < str.size(); i++ ) { if( r->next[str[i] - 'a'] == NULL ) return 0; r = r->next[str[i] - 'a']; } return r->num;}int main() { int n; while( scanf( "%d", &n ) != EOF && n ) { Node* root = createTrie(); string str[1005]; char ch = getchar(); for( int i = 0; i < n; i++ ) { cin >> str[i]; insert( root, str[i] ); } int Max = -1; int index = -1; for( int i = 0; i < n; i++ ) { int cur = find( root, str[i] ); //cout << str[i] << "="; //printf( "%d\n", cur ); if( cur > Max ) { Max = cur; index = i; } } cout << str[index] << endl; } return 0;}
0 0
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU--1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- Hdu 1004 - Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU--1004--Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise STL
- 阿里云 OCR身份证识别Api 使用(一)
- WRH$_ACTIVE_SESSION_HISTORY Does Not Get Purged Based Upon the Retention Policy (文档 ID 387914.1)
- BeautifulSoup解析网页
- hibernate中@Transient
- Mac 下的android studio获取sha1和md5
- HDU-1004 Let the Balloon Rise
- OpenCV —— Calling Cameras
- tensorflow之如何打印tensor张量的值
- http请求远程接口获得Json数据(2) --- 利用HttpClient发送post/get请求
- 软件测试江湖之公会武器之争
- 字符串的不变性170509
- TensorFlow初识
- 5.9日学习日志
- 开发过程中遇到的问题