Submission details
Task:Alien Invasion II
Sender:sspilsbury
Submission time:2020-09-19 13:20:10 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.01 sdetails

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;

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

    return 0;
}

Test details

Test 1

Verdict:

input
2368469234876449

correct output
22368469234876449
3 7456156411625483

user output
-186346292
-62115430 3

Test 2

Verdict:

input
292929292929292929292929292931

correct output
129292929292929292929292929293...

user output
-186346292
-62115430 3

Test 3

Verdict:

input
292929292929292929292929292979

correct output
129292929292929292929292929297...

user output
-186346292
-62115430 3