CSES - Aalto Competitive Programming 2024 - wk1 - Mon - Results
Submission details
Task:Babaza Game
Sender:user1111
Submission time:2024-09-02 17:56:03 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool babaza(std::string)':
input/code.cpp:5:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 |     for (int i = 0; i < a.length()-1; i++) {
      |                     ~~^~~~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < a.length(); i++) {
      |                     ~~^~~~~~~~~~~~
input/code.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < a.length(); i++) {
      |                     ~~^~~~~~~~~~~~
input/code.cpp:51:20: error: 'class std::set<char>...

Code

#include <bits/stdc++.h>
using namespace std;
 
bool babaza(string a) {
    for (int i = 0; i < a.length()-1; i++) {
        if (a[i] == a[i+1]) return false;
    }
    return true;
}
 
int main() {
	string a,b;
    cin >> a >> b;
    
    string absdiff = a;
    string ldiff = a, rdiff = a;
    for (int i = 0; i < a.length(); i++) {
        absdiff[i] = abs(b[i] - a[i]);
        if (i%2) {
            ldiff[i] = b[i];
        } else {
            rdiff[i] = b[i];
        }
    }
    if (babaza(absdiff)) {
        cout << a << '\n';
        cout << b << '\n';
        return 0;
    }
 
    if (babaza(ldiff)) {
        cout << a << '\n';
        cout << ldiff << '\n';
        cout << b << '\n';
        return 0; 
    }
    if (babaza(rdiff)) {
        cout << a << '\n';
        cout << rdiff << '\n';
        cout << b << '\n';
        return 0; 
    }
 
    set<char> used = {};
    for (int i = 0; i < a.length(); i++) {
        used.insert(a[i]);
        used.insert(b[i]);
    }
    char unused = 'A';
    for (;;unused++) {
        if (!(used.contains(unused))) {
            break;
        }
    }
    cout << a << '\n';
    for (int i = 0; i < a.length(); i++) {
        if (i%2) {
            ldiff[i] = unused;
        }
    }
    cout << ldiff << '\n';
    for (int i = 0; i < a.length(); i++) {
        if (!(i%2)) {
            ldiff[i] = b[i];
        }
    }
    cout << ldiff << '\n';
    cout << b << '\n';
    return 0; 
}