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 11:49:10
Task:Dynamic duo
Sender:oispa opiskelupaikka tefyllä ;...;
Submission time:2017-05-27 11:49:10
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;

int main(){
    
    string s; cin >> s;
    int n = s.length();
    int f[26] = {0};
    for(int i = 0; i < n; ++i){
        f[s[i]-'A']++;
        if(f[s[i]-'A'] > n/2){
            cout << -1 << endl;
            return 0;
        }
    }
    
    sort(s.begin(), s.end());
    
    for(int i = 0; i < n/2; ++i)
        cout << s[i];
    cout << endl;
    
    for(int i = n/2; i < n; ++i)
        cout << s[i];
    cout << endl;
    
    return 0;
}