-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdjacent_Shuffles.cpp
64 lines (51 loc) · 1.23 KB
/
Adjacent_Shuffles.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
// Gnanesh is working on Machine Learning domain. He wants train the machine
// in such a way that, if he provided an image printed with a string on it,
// the machine has to extract the text as a string and verify that,
// after shuffling the letters in the string, 'the shuffled string should be
// like no two adjacent letters should be same'
// You will be given extracted string, and
// Can you help Gnanesh to train the machine with the given constraint
// The machine has to print "true", if the constarint is met,
// Otherwise, print "false".
// Input Format:
// -------------
// A String S
// Output Format:
// --------------
// Print a boolean value.
// Sample Input-1:
// ---------------
// aaabd
// Sample Output-1:
// ----------------
// true
// Sample Input-2:
// ---------------
// aaab
// Sample Output-2:
// ----------------
// false
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
unordered_map<char,int> m;
for(auto i:s){
m[i]++;
}
int x=0;
if(s.size()%2!=0){
x=s.size()/2+1;
}
else{
x=s.size()/2;
}
for(auto key:m){
if(key.second>x){
cout<<"false";
exit(0);
}
}
cout<<"true";
}