-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
42 lines (37 loc) · 1011 Bytes
/
main.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
// Author : Qi Zhang
// Date : 2018-12-11
#include <bits/stdc++.h>
using namespace std;
int main()
{
string line;
while (getline(cin, line)) {
vector<int> count(26);
for(auto c: line) count[int(c-'a')]++;
unordered_map<int, int> times;
int num = 0;
for(auto c: count) {
if(c > 0){
num++;
times[c]++;
}
}
if(times.size() == 1){
cout << "YES" << endl;
continue;
}
if(times.size() == 2){
auto it = times.begin();
pair<int, int> a = *it;
++it;
pair<int, int> b = *it;
bool ans = false;
if(a.second == num-1 && abs(b.first - a.first) == 1) ans = true;
if(b.second == num-1 && abs(b.first - a.first) == 1) ans = true;
if(ans) cout << "YES" << endl;
else cout << "NO" << endl;
}
else cout << "NO" << endl;
}
return 0;
}