UVA10815 Andy's First Dictionary
来源:互联网 发布:淘宝新开店如何推广 编辑:程序博客网 时间:2024/04/28 19:23
问题链接:UVA10815 Andy's First Dictionary。
题意简述:输入一个文本文件,从中提取出字典,重复的单词被去掉。
问题分析:用C++语言编写程序,可以练习使用STL的功能。另外一点,C++编写程序效率会更高。使用STL容器类的set,可以方便地去重复,而且还会自动排序。
程序说明:使用C语言的库函数strtok()来切割单词,并且用空格' '作为分隔符。这是一种简便的做法。
另外一种切割字符串的方法是,使用STL的字符串流(sstream)实现。
AC的C++程序如下:
/* UVA10815 Andy's First Dictionary */#include <iostream>#include <cstring>#include <set>using namespace std;#define MAXN 512set<string> dict;int main(){ char s[MAXN], delim[] = " ", *p; while(cin >> s) { p = s; while(*p) { if(isalpha(*p)) *p = tolower(*p); else *p= ' '; p++; } p = strtok(s, delim); while(p) { dict.insert(p); p = strtok(NULL, delim); } } for(set<string>::iterator iter =dict.begin(); iter != dict.end(); iter++) cout << *iter << "\n"; return 0;}
1 0
- uva10815 - Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVa10815 - Andy's First Dictionary
- UVa10815 Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVA10815 - Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVa10815 Andy's First Dictionary
- UVA10815 - Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVA10815 - Andy's First Dictionary
- uva10815 Andy's First Dictionary
- UVa10815 Andy's First Dictionary
- UVA10815 Andy`s first dictionary
- UVa10815,Andy's First Dictionary, set,stringstream
- uva10815 Andy's First Dictionary(集合)
- Uva10815——Andy's First Dictionary
- 127.Identify the two situations in which the alert log file is updated with details. (Choose two.)
- androidStudio com.android.build.api.transform.TransformException解决方案
- Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy...
- Light OJ:1094 Farthest Nodes in a Tree(树状DP+统计树的最大直径)
- java基础总结(摘抄)
- UVA10815 Andy's First Dictionary
- Unity、NGUI性能优化方法总结
- 链表——灵活的“数组”(链表的操作)
- application
- 详细介绍Java中堆、栈 和常量池的不同使用
- Python随学随记(6)
- 作为一个程序员我为什么要写博客?
- fastdfs分布式文件系统之tracker server介绍
- [读书笔记] 把时间当朋友