forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.cpp
37 lines (35 loc) · 814 Bytes
/
solution.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
#include <iostream>
#include <set>
using namespace std ;
int main ()
{
// input the number of options to perform
int n ;
cin >> n ;
set < string > s ;
set < string > :: iterator it ;
while ( n -- )
{
// input the operations
string a , b ;
cin >> a >> b ;
if ( a == "add" )
{
s.insert ( b ) ;
}
else
{
it = s.lower_bound ( b ) ;
int counter = 0 ;
int len = b.length () ;
while ( it != s.end () && b == (*it).substr ( 0 , len ) )
{
counter ++ ;
it ++ ;
}
// print the number of contact names starting with input string
cout << counter << endl ;
}
}
return 0 ;
}