-
Notifications
You must be signed in to change notification settings - Fork 0
/
bing.cpp
52 lines (45 loc) · 1.2 KB
/
bing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int> seen; // Stores the times a prefix has been seen
// For each case
int t;
cin >> t;
while(t-- > 0)
{
// Get the word
string word;
cin >> word;
// If this word hasn't been seen as a prefix
if(seen.count(word) == 0)
{
cout << 0 << endl;
}
// If this word has been seen as a prefix
else
{
// Print the number of times this prefix has been seen
cout << seen[word] << endl;
}
string sub = ""; // Stores the current prefix
// For each character in the word
for(int i = 0; i < word.size(); i++)
{
sub.push_back(word[i]); // Add the word to the current prefix
// If the current prefix hasn't been seen
if(seen.count(sub) == 0)
{
// Set it as seen once
seen[sub] = 1;
}
// If the current prefix has been seen
else
{
// Increment the nuber of times seen
seen[sub]++;
}
}
}
return 0;
}