-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAcronym_String.cpp
75 lines (63 loc) · 1.93 KB
/
Acronym_String.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
// Ananth interested in creating the acronyms for any word. The definition
// of acronym is another word with a concatenation of its first letter,
// the number of letters between the first and last letter, and its last letter.
// If a word has only two characters, then it is an acronym of itself.
// Examples:
// - Acronym of 'fog' is f1g'.
// - Acronym of 'another' is 'a5r'.
// - Acronym of 'ab' is 'ab'.
// You are given a list of vocabulary, and another list of words.
// Your task is to check,each word with the vocabulary and
// return "true" if atleast one of the following rules satisfied:
// 1. acronym of the word should not match with any of the acronyms of vocabulary
// 2. if acronym of the word matches with any of the acronyms of vocabulary
// 'the word' and matching words in vocabulary should be same.
// Otherwise, return 'false'.
// Input Format:
// -------------
// Line-1: Space separated strings, vocabulary[]
// Line-2: Space separated strings, words[]
// Output Format:
// --------------
// Print N boolean values, where N = words.length
// Sample Input-1:
// ---------------
// cool bell cool coir move more mike
// cool char move
// Sample Output-1:
// ----------------
// true false false
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<string> v1;
string s1,t1;
getline(cin,s1);
stringstream x1(s1);
while(getline(x1,t1,' ')){
v1.push_back(t1);
}
string s2,t2;
getline(cin,s2);
stringstream x2(s2);
while(getline(x2,t2,' ')){
int flag=0;
for(string s:v1){
if(t2[0]==s[0] && t2[t2.size()-1]==s[s.size()-1]){
if(t2==s){
continue;
}
else{
flag=1;
break;
}
}
}
if(flag==0){
cout<<"true"<<" ";
}
else{
cout<<"false"<<" ";
}
}
}