Rezultati

Up. imeNalogaJezikRezultatČas oddaje
Muf Sveti gral C++ 100/100OK 10. maj '18 @ 17:25

Test Točke Porabljen spomin Porabljen čas Status
#1 5/5 3,031 MiB 0,000 s OK
#2 5/5 3,035 MiB 0,004 s OK
#3 5/5 3,105 MiB 0,000 s OK
#4 5/5 3,105 MiB 0,004 s OK
#5 5/5 3,031 MiB 0,000 s OK
#6 5/5 3,031 MiB 0,000 s OK
#7 5/5 3,035 MiB 0,004 s OK
#8 5/5 3,105 MiB 0,000 s OK
#9 6/6 3,035 MiB 0,004 s OK
#10 6/6 3,105 MiB 0,000 s OK
#11 6/6 3,031 MiB 0,004 s OK
#12 6/6 3,027 MiB 0,000 s OK
#13 6/6 3,031 MiB 0,004 s OK
#14 6/6 3,105 MiB 0,004 s OK
#15 6/6 3,105 MiB 0,004 s OK
#16 6/6 3,035 MiB 0,000 s OK
#17 6/6 3,035 MiB 0,000 s OK
#18 6/6 3,105 MiB 0,004 s OK

Ocenjevani program (svgral.cpp):
#include <iostream>
#include <sstream>
#include <cmath>
#include <deque>
using namespace std;
int count_stevk(int n) {
    int i = 0;
    while(n!=0) {
        n/=10;
        ++i;
    }
    return i;
}
int *to_stevke(int num) {
    int * stevke = new int[10];
    for(int i = 0; i < 10; ++i) {
        stevke[i] = 0;
    }
    int i = 0;
    while(num != 0) {
        stevke[9-i] = num%10;
        num/=10;
        ++i;
    }
    return stevke;
}
void povecajEna(int *n) {
    for(int i = 9; i >= 0; --i) {
        ++n[i];
        if(n[i] <= 9) {
            break;
        }
        else n[i] = 0;
    }
}

int main()
{
    int n;
    cin >> n;

    int stevke[10];
   
    int st = count_stevk(n);

    int m = n - st * 9;
    int *stevke_cur = to_stevke(m);

    int c_stevk = 9;
    deque<int> solutions;
    while(m < n) {

        // preveri stevilo
        int sum = m;
        for(int i = 0; i < 10; ++i) {
            sum += stevke_cur[i];
            // sum += stevke_cur[i] * pow(10, 9-i);
        }
        // cout << sum << endl;
        if (sum == n) {
            solutions.push_back(m);
        }
        
        // povecaj
        povecajEna(stevke_cur);
        ++m;
        --st;
    }
    cout << solutions.size() << endl;
    for(int i = 0; i < solutions.size(); ++i) {
        cout << solutions.at(i) << endl;
        // cout << stevke_cur[i];
    }
}