sdnu1099.前缀判断
2017-11-10 17:51
225 查看
1099.前缀判断
Time Limit: 1000 MS Memory Limit: 32768 KB
Total Submission(s): 421 Accepted Submission(s): 58
Description
给定 n 个字符串,求有多少字符串是其他字符串的前缀。
Input
第一行为一个整数n(1 <= n <= 1000),之后n行,每行一个字符串,字符串只由26个小写字母组成,最大长度为100。
Output
一个整数,有多少字符串是其他字符串的前缀。
Sample Input
5
abcde
ab
bcde
b
cde
Sample Output
2
Source
Unknown
Time Limit: 1000 MS Memory Limit: 32768 KB
Total Submission(s): 421 Accepted Submission(s): 58
Description
给定 n 个字符串,求有多少字符串是其他字符串的前缀。
Input
第一行为一个整数n(1 <= n <= 1000),之后n行,每行一个字符串,字符串只由26个小写字母组成,最大长度为100。
Output
一个整数,有多少字符串是其他字符串的前缀。
Sample Input
5
abcde
ab
bcde
b
cde
Sample Output
2
Source
Unknown
#include<cstdio> #include<iostream> #include <cmath> #include<string> #include<set> #include<iterator> #include<cstring> using namespace std; #define N 10001 using namespace std; int main() { int n,t=0,b,a; string c[1010]; set <string> s; //存储所有前缀 set <string> p; //判断是否出现过重复字符串 set <string> chu; //存储重复出现过的字符串 cin >> n; for(int i=0; i<n; i++){ cin >> c[i]; if(p.count(c[i])) //判断是否出现过重复字符串 { chu.insert(c[i]); //将重复出现的字符串放入其中 } p.insert(c[i]); //cout << c[i].length() <<endl; for(int j=1; j<c[i].length(); j++){ string str=c[i].substr(0,j); //找出所有的前缀放入s中 s.insert(str); } } for(int i=0; i<n; i++){ if(chu.count(c[i])) //如果重复出现过,他一定是其他字符串的前缀 t++; else if(s.count(c[i])) //如果他是其他字符串的前缀 t++; else continue; } cout << t << endl; return 0; }
相关文章推荐
- sdnu 1099 前缀判断
- sdnu oj 1099 前缀判断
- SDNUOJ1099前缀判断(set)
- HDU 5776 sum (BestCoder Round #85 A) 简单前缀判断+水题
- sdnu 1099
- poj Phone List 3630 (字典树 判断前缀)
- hdu 1671(字典树判断前缀)
- sdnu第一场选拔赛--Miller_Rabin算法判断是否为素数
- (hdu step 5.2.3)Phone List(Trie实现:在一堆号码中,判断是否有号码是其他号码的前缀)
- hdoj Immediate Decodability 1305 (字典树判断前缀)
- [leetcode] Longest Common Prefix 字符窜最长公共前缀判断
- 前缀判断 - 蓝桥杯
- 2013年第四届蓝桥杯C/C++程序设计本科B组省赛 前缀判断(代码填空)
- poj 1056 判断前缀
- 将数字转换为字符串、将字符串转换为数字,判断前缀,后缀
- 前缀判断
- 1426. Phone List(把电话号码排序,再判断相邻的是否为前缀关系)
- 前缀判断 - 蓝桥杯
- Lua判断字符串前缀是否为指定字符的3种方法
- Immediate Decodability(字典树-判断是否存在前缀)