UVA-10815 - Andy's First Dictionary
2016-07-13 16:29
501 查看
UVA-10815 - Andy’s First Dictionary
题目大意:把一篇文章中所有的单词按字典序排列解题思路:读取单词后排序,去除重复的单词
···题目没看好,最多有5000个词但是词超过5000个,开的数组不过打Runtime-error,排序也不能用O(n^2)的,超时,最后用qsort= =过了
#include<cstdio> #include<string> #include<iostream> #include<cstring> #include<algorithm> using namespace std; char map[50100][210]; int cmp(const void* _a,const void* _b) { char* a= (char*)_a; char* b= (char*)_b; return strcmp(a,b); } bool flag[50100]; int main() { char c,tmp[205]; int i=0,j=0; while((c=getchar())!=EOF) { if(!isalpha(c)) { if(j>0) { tmp[j]='\0'; strcpy(map[i],tmp); i++; } j=0; } else { tmp[j]=tolower(c); j++; } } char temp[210]; int n=i-1; qsort(map,n+1,210,cmp); for(int i=0;i<=n;i++) {if(strcmp(map[i],map[i+1])==0) continue; puts(map[i]); } return 0; }
相关文章推荐
- docker 常用命令
- (第14讲)哈希表的开放地址法中的二次探测
- Oracle同义词创建及其作用
- unity Shader 描边
- 我不是产品经理-006
- (15.1.19)我的 Android 开发实战经验总结
- InstallShield Limited Edition for Visual Studio 2013 图文教程
- [数学 高精度] HDU 5241 Friends
- C 实现ArrayMap字典映射
- flume+kafka 积累一波
- 没有了剪辑和台本,papi酱为何要“强行”直播
- iOS开发进阶
- uva-10878 - Decode the tape
- 深入浅出RxJava就这一篇就够了
- C#/.net学习-----C#基础知识
- css系列(布局):实现一个元素在浏览器中水平、垂直居中的几个方案
- codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理
- [leetcode]climbing-stairs 动态规划 C++
- Umbraco 官方技术文档 翻译 一 、BackOffice overview
- 动态代理实现数据库连接池功能(代理Connection的close方法)