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:54
Task:Dynamic duo
Sender:HIIT AND RUN
Submission time:2017-05-27 11:49:54
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:18:17: warning: array subscript has type 'char' [-Wchar-subscripts]
         asd[s[i]]++; 
                 ^
input/code.cpp:32:21: warning: array subscript has type 'char' [-Wchar-subscripts]
         while (asd[i] > 0) {
                     ^
input/code.cpp:33:18: warning: array subscript has type 'char' [-Wchar-subscripts]
             asd[i]--;
                  ^
input/code.cpp:35:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (a.size() == n/2) break;
                               ^
input/code.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (a.size() == n/2) break;
                           ^
input/code.cpp:42:21: warning: array subscript has type 'char' [-Wchar-subscripts]
         while (asd[i] > 0) {
                     ^
input/code.cpp:43:18: warning: array subscript has type 'char' [-Wchar-subscripts]
             asd[i]--;
                  ^
input/code.cpp:45:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (b.size() == n/2) break;
                               ^
input/code.cpp:47:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (b.size() == n/2) break;
                           ^

Code

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int asd[256];

int main() {
    ios_base::sync_with_stdio(0);

    string s;
    cin >> s;
    ll n = s.size();
    


    for (int i = 0; i < n; i++) {
        asd[s[i]]++; 
    }
    
    for (int i = 0; i < 256; i++) {
        if (asd[i] > (n / 2)) {
            cout << "-1" << endl;
            return 0;
        }
    }
    
    string a = "";
    string b = "";
    
    for(char i = 'A'; i <= 'Z'; i++) {
        while (asd[i] > 0) {
            asd[i]--;
            a += i;
            if (a.size() == n/2) break;
        }
        if (a.size() == n/2) break;
    }
    
    
    for(char i = 'A'; i <= 'Z'; i++) {
        while (asd[i] > 0) {
            asd[i]--;
            b += i;
            if (b.size() == n/2) break;
        }
        if (b.size() == n/2) break;
    }

    cout << a << endl;
    cout << b << endl;
    
}