sdnu oj 1099 前缀判断
2017-11-11 18:28
197 查看
1099.前缀判断
Time Limit: 1000 MS Memory Limit: 32768 KBTotal Submission(s): 436 Accepted Submission(s): 63
Description
给定 n 个字符串,求有多少字符串是其他字符串的前缀。
Input
第一行为一个整数n(1 <= n <= 1000),之后n行,每行一个字符串,字符串只由26个小写字母组成,最大长度为100。
Output
一个整数,有多少字符串是其他字符串的前缀。
Sample Input
5 abcde ab bcde b cde
Sample Output
2
Source
UnknownSubmitStatisticDiscuss
© 2012-2015 SDNU ACM-ICPC TEAM, v1.2 Beta
这道题师哥们规定了要用set来做。所以先自学set后再来做这个题,需要注意的都在备注上。
Source Code View
Run ID: 57517 / Problem ID: 1099 / Author: 2017Liushilei / Language: C++
Submit Time: 2017-11-11 18:22:57 / Judge Status: Accepted /
Judge Time: 2017-11-11 18:23:00
1
#include<cstdio>
2
#include<iostream>
3
#include <cmath>
4
#include<string>
5
#include<set>
6
#include<iterator>
7
#include<cstring>
8
using namespace std;
9
#define N 10001
10
using namespace std;
11
int main()
12
{
13
int n,t=0,b,a;
14
string c[1010];
15
set <string> s; //存储所有前缀
16
set <string> p; //判断是否出现过重复字符串
17
set <string> chu; //存储重复出现过的字符串
18
cin >> n;
19
for(int i=0; i<n; i++){
20
cin >> c[i];
21
if(p.count(c[i])) //判断是否出现过重复字符串
22
{
23
chu.insert(c[i]); //将重复出现的字符串放入其中
24
}
25
p.insert(c[i]);
26
//cout << c[i].length() <<endl;
27
for(int j=1; j<c[i].length(); j++){
28
string str=c[i].substr(0,j); //找出所有的前缀放入s中
29
s.insert(str);
30
}
31
}
32
for(int i=0; i<n; i++){
33
if(chu.count(c[i])) //如果重复出现过,他一定是其他字符串的前缀
34
t++;
35
else if(s.count(c[i])) //如果他是其他字符串的前缀
36
t++;
37
else continue;
38
}
39
cout << t << endl;
40
return 0;
41
}
相关文章推荐
- SDNUOJ1099前缀判断(set)
- sdnu 1099 前缀判断
- sdnu1099.前缀判断
- 2013蓝桥杯 前缀判断 【初赛试题】
- (hdu step 5.2.3)Phone List(Trie实现:在一堆号码中,判断是否有号码是其他号码的前缀)
- poj 1056 判断前缀码
- 前缀判断
- hdu1671Phone List(字典树---判断有无相同的前缀单词)
- hdu Phone List 字典树的前缀判断
- 判断一个序列是否是另一个序列的前缀
- 前缀判断
- 1005-前缀判断
- 蓝桥杯--前缀判断
- Lua判断字符串前缀是否为指定字符的3种方法
- 将数字转换为字符串、将字符串转换为数字,判断前缀,后缀
- JavaScript判断各浏览器CSS前缀的两种方式
- NSString基础2-判断前缀、后缀、分割、截取、拼接、查询
- 前缀判断 - 蓝桥杯
- poj--3630--Phone List(字典树+前缀判断)
- 1426. Phone List(把电话号码排序,再判断相邻的是否为前缀关系)