Submission details
Task:Alien Invasion II
Sender:sspilsbury
Submission time:2020-09-19 13:19:54 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:49:5: error: 'assert' was not declared in this scope
     assert (factor * 3 == res);
     ^~~~~~
input/code.cpp:49:5: note: suggested alternative: 'qsort'
     assert (factor * 3 == res);
     ^~~~~~
     qsort

Code

#include <vector>
#include <iostream>

template <typename T>
void print_array(std::vector<T> const &x) {
    for (auto y : x) {
        std::cout << y << " ";
    }

    std::cout << std::endl;
}

int main(void) {
    int in = 0;
    std::cin >> in;

    std::vector<int> x;
    int sum = 0;

    // Always divisible by 3 if the sum of all digits is
    // divisible by 3
    while (in != 0) {
        int d = in % 10;
        x.push_back(d);
        in /= 10;

        sum += d;
    }

    // Now we have all the digits and the sum, just figure
    // out what needs to be added by taking the sum modulo
    // 3 and adding that
    int m3 = sum % 3;
    x.push_back(3 - m3);

    // Now we need to make a number, pop a number off the top
    // and multiply by 10 each time
    int res = 0;
    for (int i = (x.size() - 1); i >= 0; --i) {
        res += x[i];
        res *= 10;
    }

    res /= 10;

    // Ok now that we have the number, should be divisible by 3
    int factor = res / 3;

    assert (factor * 3 == res);

    std::cout << res << std::endl;
    std::cout << factor << " " << 3 << std::endl;

    return 0;
}