Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define DIM 8000005
- #define ALPHABET_SIZE 'z'-'a'+1
- using namespace std;
- int TRIE[DIM][ALPHABET_SIZE];
- bool used[DIM];
- int sz = 1;
- vector<string> repeated;
- void build();
- void add(string s);
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int n;
- string s;
- build();
- cin >> n;
- while(n--){
- cin >> s;
- if(s.length()>=4)
- add(s);
- }
- if(repeated.empty()){
- cout << "SAFO\n";
- }else{
- cout << repeated.size() << "\n";
- for(int i=0;i<repeated.size();i++){
- cout << repeated[i] << "\n";
- }
- }
- return 0;
- }
- void build(){
- for(int i=0;i<DIM;i++){
- used[i] = 0;
- for(int j=0;j<ALPHABET_SIZE;j++){
- TRIE[i][j] = -1;
- }
- }
- return;
- }
- void add(string s){
- int node = 0;
- for(int i=0;i<s.length();i++){
- if(TRIE[node][s[i]]==-1){
- TRIE[node][s[i]] = sz++;
- }
- node = TRIE[node][s[i]];
- }
- if(used[node]){
- repeated.push_back(s);
- }
- used[node] = 1;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement