-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloseStrings.cpp
More file actions
40 lines (37 loc) · 906 Bytes
/
Copy pathcloseStrings.cpp
File metadata and controls
40 lines (37 loc) · 906 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
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
bool closeStrings(string word1, string word2)
{
const int l1 = word1.length();
const int l2 = word2.length();
if (l1 != l2)
return false;
vector<int> f1(26), f2(26);
vector<int> s1(26), s2(26);
for (char c : word1)
++f1[c-'a'], s1[c-'a'] = 1;
for (char c : word2)
++f2[c-'a'], s2[c-'a'] = 1;
sort(begin(f1), end(f1));
sort(begin(f2), end(f2));
for(int i : s1)
cout<<i;
cout<<'\n';
for(int i : s2)
cout<<i;
cout<<'\n';
return f1 == f2 && s1 == s2;
}
};
int main()
{
string word1, word2;
cin >> word1 >> word2;
if (Solution().closeStrings(word1, word2))
cout << "Close strings\n";
else
cout << "Not close strings\n";
}