Phone List POJ3630
来源:互联网 发布:2016淘宝女装销量前十 编辑:程序博客网 时间:2024/06/06 10:53
题目:http://poj.org/problem?id=3630
题意很易懂,判断是否有电话号码是其他号码的前几位,关键在于不超时。
思路:按字典序排序后遍历判断是否有相邻两个号码短的是长的的前缀。
注:(1)string比较慢,考察超时的题尽量别用。
我就见过有同学用流读入然后超时的(手动滑稽)
语言:c风格的c++
#include <iostream>#include <cstdio>#include <cstring>#include <cctype>#include <cstdlib>using namespace std;char s[10010][20];int cmp(const void *a, const void *b){ return strcmp((char *)a, (char *)b);}bool str_cmp(int a){ int len = min(strlen(s[a-1]), strlen(s[a])); int i; for(i=0;i<len;i++) { if(s[a-1][i]!=s[a][i]) return false; } return true;}int main(){ int cases; int i,j,k,len,n,t; cin >> cases; while(cases--) { cin >> n; for(i=0;i<n;i++) { scanf("%s", s[i]); } qsort(s, n, sizeof(s[0]), cmp); t = 0; for(i=1;i<n;i++) { if(str_cmp(i)) { t = 1; break; } } if(t==0) { puts("YES"); } else { puts("NO"); } } return 0;}
0 0
- poj3630 phone list
- poj3630 Phone List
- POJ3630 Phone List
- POJ3630 Phone List
- poj3630 Phone List
- POJ3630 Phone List
- poj3630 Phone List
- Phone List POJ3630
- poj3630/hdu1671 Phone List
- poj3630(Phone List+字典树)
- Phone List(poj3630,字典树)
- poj3630 Phone List与Trie
- POJ3630 - Phone List - 二叉树
- POJ3630 Phone List(字典树)
- poj3630 Phone List 字典树
- POJ3630 Phone List 题解&代码
- POJ3630 Phone List(字典树)
- 【poj3630】Phone List 【Nordic 2007】
- 1
- PHP大数据之加减乘除
- LINQ 简介
- jpa一些查询方法
- Android开发中逐步取代MVC的MVP架构知多少?
- Phone List POJ3630
- STL中坑爹的max函数
- Cocos2d-x 3.x 图形学渲染系列三十
- 安装微擎时遇到的几个问题
- 自定义浏览器滚动条的样式,打造属于你的滚动条风格
- Codeforces Round #395 (Div. 2) A+B
- GZIP概念
- 第一次来写博客
- IntelliJ IDEA单元测试入门