Rezultati

Up. imeNalogaJezikRezultatČas oddaje
sSrcem-2018 Sveti gral C++ 100/100OK 10. maj '18 @ 18:59

Test Točke Porabljen spomin Porabljen čas Status
#1 5/5 3,230 MiB 0,004 s OK
#2 5/5 3,230 MiB 0,000 s OK
#3 5/5 3,223 MiB 0,004 s OK
#4 5/5 3,160 MiB 0,000 s OK
#5 5/5 3,152 MiB 0,000 s OK
#6 5/5 3,160 MiB 0,369 s OK
#7 5/5 3,223 MiB 0,412 s OK
#8 5/5 3,156 MiB 0,376 s OK
#9 6/6 3,230 MiB 0,000 s OK
#10 6/6 3,160 MiB 0,004 s OK
#11 6/6 3,160 MiB 0,000 s OK
#12 6/6 3,219 MiB 0,004 s OK
#13 6/6 3,160 MiB 0,004 s OK
#14 6/6 3,223 MiB 0,004 s OK
#15 6/6 3,230 MiB 0,004 s OK
#16 6/6 3,289 MiB 0,000 s OK
#17 6/6 3,156 MiB 0,004 s OK
#18 6/6 3,230 MiB 0,406 s OK

Ocenjevani program (sveti_gral.cpp):
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// Za desetice daš enico
// Za stotice daš desetice


void getMin(unsigned int N, unsigned int& MIN) {
    unsigned int N_tmp = N;
    string n = to_string(N);

    bool d = false;
    for( short i = 1; i < n.size(); i++ ) {
        if( n[i] != '9' ) {
            d = true;
            break;
        }
    }
    
    if( d ) {
        N_tmp = stoi( to_string(((int)n[0] - 48)-1) + string( n.size()-1,'9' ) );
    }
    else {
        N_tmp = N;
    }


    unsigned int tmp = 0;
    string n2 = to_string(N_tmp);

    if( n.size() < 6 ) {
        for( short i = 0; i < n2.size(); i++ ) {
            int a = (int)n2[i] - 48;
            tmp += a;
        }
        MIN = N_tmp - tmp;
    }
    else if( n.size() == 8 ){
        MIN = N - 1000000;
    }
    else {
        MIN = N - 1000000;
    }
}

void getValues(unsigned int N, unsigned int& MIN, unsigned int& MAX, vector<unsigned int> &values ) {
    for( unsigned int i = MIN; i < N; i++ ) {
        string abba = to_string(i);
        unsigned gaba = 0;
        for( short l = 0; l < abba.size(); l++ ) {
            gaba += (int)abba[l] - 48;           
        }
        if( i + gaba == N ) {
            values.push_back(i);
        }
    }
}


int main(int argc, char* argv[]) 
{
    unsigned int N, MIN, MAX;
    vector<unsigned int> values;

    cin >> N;
    
    getMin(N,MIN);

    getValues(N, MIN, MAX, values);

    cout << values.size() << endl;
    for( auto i : values) {
        cout << i << endl;
    }

    return 0;
}