-
Notifications
You must be signed in to change notification settings - Fork 0
/
499B.cpp
84 lines (75 loc) · 1.42 KB
/
499B.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// USING MAPS 👌👌👍💕
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
map <string,string> a;
cin>>n>>m;
string s,t;
while(m--)
{
cin>>s>>t;
a[s]=(t.size()<s.size()?t:s);
}
while(n--)
{
cin>>s;
cout<<a[s]<<' ';
}
}
// BRUTE FORCE 👍👍🌹
#include <bits/stdc++.h>
using namespace std;
int find(string str, string s[], int m){
for (int i = 0; i < m; i++)
{
if(str==s[i])
return i;
else
continue;
}
}
int main(){
int n,m;
cin>>n>>m;
//int a[m*2];
string s[m*2];
m=m*2;
for (int i = 0; i < m; i++)
{
cin>>s[i];
}
string f[n];
for (int i = 0; i < n; i++)
{
cin>>f[i];
}
for (int i = 0; i < n; i++)
{
//cin>>s[i];
string str=f[i];
int p=find(str,s,m);
if(p%2==0){
string s1=s[p];
string s2=s[p+1];
if(s1.length()==s2.length())
cout<<s1<<" ";
else if(s1.length()<s2.length())
cout<<s1<<" ";
else
cout<<s2<<" ";
}
if(p%2!=0){
string s2=s[p];
string s1=s[p-1];
if(s1.length()==s2.length())
cout<<s1<<" ";
else if(s1.length()<s2.length())
cout<<s1<<" ";
else
cout<<s2<<" ";
}
}
//cout<<s[0]<<" "<<s[1];
}