-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp4.cpp
More file actions
49 lines (43 loc) · 837 Bytes
/
Copy pathp4.cpp
File metadata and controls
49 lines (43 loc) · 837 Bytes
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
/*
check a given word contains the words in a dictionary
(this pgm has two solutions)
*/
#include<iostream>
#include<string>
#include<map>
using namespace std;
void efficient(string, string);
int main()
{
string s1,s2,s3;
cin>>s1>>s2;
int k=0;
for(int i=0;i<s2.length();i++)
{
for(int j=0;j<s1.length();j++)
{
if(s1[j] != s2[i])
{
s3 += s1[j];
}
}
s1 = s3;
s3.clear();
}
// cout<<s1<<endl;
efficient(s1,s2);
}
void efficient(string s1, string s2)
{
map<char,int> mapping;
string s3;
map<char,int>::iterator it;
for(int i=0;i<s2.length();i++)
mapping[s2[i]] = i;
for(int j=0;j<s1.length();j++)
{
if(mapping.find(s1[j]) == mapping.end())
s3+=s1[j];
}
cout<<s3<<endl;
}