题目:统计单词。

分析:字符串处理、字典树。比较裸的字典树,建树输出即可。

注意:库iostream中没有gets。万恶的CE,╮(╯▽╰)╭。

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>using namespace std;//Trie
typedef struct node1
{bool   flag;node1 *next[26];
}tnode;
tnode dict[50000];class Tire
{tnode* root;int    size;char   save[201];public:Tire() {size = 0;root = newnode();}int ID( char ch ) {if ( ch <= 'Z' ) return ch-'A';else return ch-'a';}//构造新节点 tnode* newnode() {for ( int i = 0 ; i < 26 ; ++ i )dict[size].next[i] = NULL;dict[size].flag = false;return &dict[size ++]; }//单词插入 void insert( char* word, int len ) {tnode *now = root;for ( int i = 0 ; i < len ; ++ i ) {if ( !now->next[ ID(word[i]) ] )now->next[ ID(word[i]) ] = newnode();now = now->next[ ID(word[i]) ];}now->flag = true;}//利用dfs遍历输出 void output( tnode* r, int d ) {if ( r->flag ) {save[d] = 0;puts(save);}for ( int i = 0 ; i < 26 ; ++ i )if ( r->next[i] ) {save[d] = i+'a';output( r->next[i], d+1 );}}void output(){ output(root,0); }
};
//Tire endint main()
{char buf[201],sav[201];Tire tire;while ( gets(buf) ) {int len = strlen(buf);int cou = 0;for ( int i = 0 ; i <= len ; ++ i )if ( (buf[i] >= 'a' && buf[i] <= 'z') ||(buf[i] >= 'A' && buf[i] <= 'Z') )sav[cou ++] = buf[i];else if ( cou ) {sav[cou] = 0;tire.insert( sav, cou );cou = 0;}}tire.output();return 0;
}

UVa 10815 - Andy's First Dictionary相关推荐

  1. UVA 10815 Andy's First Dictionary(STL: set)

    代码如下: #include <iostream> #include <sstream> #include <stdio.h> #include <set&g ...

  2. uvaoj 10815 Andy's First Dictionary set的基本使用

    uvaoj 10815 Andy's First Dictionary set的基本使用 将单词去重后按照字典序输出. 代码如下: /********************************* ...

  3. UVa 11062 Andy's Second Dictionary(刘汝佳紫书升级题)

    在介绍这道题之前,先介绍一下紫书里面和这道题很像的一道题: 紫书P112页 的例题5-3 安迪的第一个字典(Andy's First Dictionary UVa 10815) 原题链接如下: And ...

  4. 10815 - Andy's First Dictionary

    Andy's First Dictionary PS:因为该题排版较麻烦,这里给出OJ网址:UVa10815 - Andy's First Dictionary 输入一个文本,找出所有不同的单词(连续 ...

  5. 《STL》— UVa10815 Andy's First Dictionary

    UVa10815 Andy's First Dictionary 题意:输入一个文本,找出所有不同的单词(连续字母序列),按字典序从小到大输出.单词不分大小写. #include<string& ...

  6. 【UVA - 10815】 Andy's First Dictionary(STL+字符处理)

    题干: Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for ...

  7. [STL] UVA 10815 安迪的第一个字典 Andy's First Dictionary

    1.set 集合 哦....对了,set有自动按照字典序排序功能..... 声明和插入操作 #include <cstdio> #include <vector> #inclu ...

  8. 例题5-3 安迪的第一个字典(Andy's First Dictionary,Uva 10815)

    #include<bits/stdc++.h> using namespace std; set<string> dict; int main(){string s,buf;w ...

  9. 例5-3 安迪的第一个字典(Andy‘s First Dictionary,UVa 10815)

    注意使用stringstream得到各个单词 #include <iostream> #include <string> #include <set> #inclu ...

  10. 字符串训练 ----- UVA 10815题目Andy's First Dictionary

    解题思路: 本题主要是涉及分割获取单词  然后按字典排序输出单词 (这个只要用qsort排序下就好了) AC代码如下 #include <iostream> #include <st ...

最新文章

  1. app.config自定义配置节点
  2. 内容组织高效项目方案是如何产生的 !
  3. web前端html图片轮播,如何使用LayUI实现网页轮播图_WEB前端开发,layui,轮播图
  4. 使用IE WebControls中的TabStrip控件和MultiPage控件实现选项卡式风格页面(转载)
  5. Futura:从纳粹主义到月球-甚至更远
  6. SNMP学习之结构体snmp_secmod_def
  7. mysql提取前两个数据_各种数据库提取表的前几条记录的方法
  8. Android反编译方法
  9. 微信撤回软件安卓版_微信无限时间撤回软件
  10. 打印机出现另存为xps_打印机打印文件时弹出另存为xps/pdf该怎办?
  11. Element DatePicker 日期选择器限定日期选择范围
  12. Win10怎么去除桌面快捷方式图标左下角的小箭头
  13. 创业半年回顾(没饭吃了,我再也不想创业了)
  14. 【前端灵魂脚本语言JavaScript⑤】——JS中数组的使用
  15. 搬砖: web音频流转发之音视频直播
  16. 将GIF转成视频MP4、MOV
  17. [倚天屠龙记] vim 查找与替换(简单查找)
  18. 单调函数必有反函数,但为何有反函数的不一定是单调函数
  19. C++网络摄像头数据的获取与显示 (续)
  20. linux下强制卸载命令,强制删除rpm包的方法

热门文章

  1. linux下rsync服务的搭建
  2. Windows PowerShell是啥?看完本文你就懂它了
  3. 关于LED 流水灯的软件调试方法(非开发板调试)
  4. ANDROID常用的命令(转载,后续自己完善)
  5. 1049. Counting Ones
  6. 经典推荐:08年草根站长现状360度总结分析
  7. 学习C++必须掌握的概念
  8. MySQL索引类型及优化
  9. Hadoop环境共享
  10. PWM DAC vs. Standalone