Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 13:15:54
2017-05-27 13:03:09
Task:Dynamic duo
Sender:IOG
Submission time:2017-05-27 13:15:54
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
 cin.sync_with_stdio(0);
 cin.tie(0);
 string s;
 unordered_map<char, int> map;
 cin >> s;
 int len = s.size();
 
 for (unsigned int i = 0; i < s.size(); ++i)
 {
     if (map[s[i]] < 1)
        map[s[i]] = 1;
     else
         map[s[i]] += 1;
 }
 
 for (auto x : map)
 {
     int count = x.second;
     //cout << count << "\n";
     
     if (count > len/2) {
         cout << "-1" << endl;
         return 0;
     }
 }
 
 string res;
 
 for (auto x : map)
 {
        int occur = x.second;
        for (int i = 0; i < occur; ++i)
        {
            res += x.first;
        }
 }
 
 
 /*string a(res, res + len/2);
 string b(res + len/2, res.end());
 cout << a << endl;
 cout << b << endl;*/
 
 for (int i = 0; i < len/2; ++i)
 {
     cout << res[i];
 }
 
 
 cout << "\n";
 
 for (int i = (len/2); i < len; ++i)
 {
     cout << res[i];
 }
     cout << endl;
}