1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
struct Poz{
    int i;// indexy do sortowania
    int d;//kolejny dzien
    int cyfra[11];//a dlaczego nie, bedzie porzadek :)
    //se mozna pozwolic
}a;

//metody sortowania wedlug dni
bool dni(const Poz &a, const Poz &b){
    return a.d < b.d;
}

//sortowanie indexami na powrot
bool indeksy(const Poz &a, const Poz &b){
    return a.i < b.i;
}

//rekurencyjne mnozonko
int mnoz(int x){
    if(x<10)
        return x;
    else
        return x%10 * mnoz(x/10);
}
bool debug = false;
int cyfry[11]={0},x,t;
int maxA = -1;
vector<Poz> tab;

int main(){
    //wczytaj dane
    scanf(" %d",&t);
    for(int i=0; i<t; i++){
        scanf(" %d",&a.d);
        if(a.d > maxA)
            maxA = a.d;
        a.i = i;
        tab.push_back( a );
    }
    a.i=t;
    a.d=2140000000;
    tab.push_back( a );
    //wez posortuj wedlug dni
    sort(tab.begin(),tab.end(),dni);

    if(debug){
        for(int i=0; i<t; i++){
            printf("%d ",tab[i].i);
        }
    }
    //pozycja kolejnego dnia z zapytania
    int poz = 0;
    //int wartpoz = tab[poz].d;
    for(int i=1; i<=maxA; i++){
        x = i;

        while(x>=10){
            x = mnoz(x);
        }

        cyfry[x]++;

        while(i == tab[poz].d){
            for(int j=0; j<10; j++)
                tab[poz].cyfra[ j ] = cyfry[ j ];
            poz++;
            //wartpoz = tab[poz].d;
        }

    }

    sort(tab.begin(),tab.end(),indeksy);
    if(debug){
        printf("\n");
        for(int i=0; i<t; i++){
            printf("%d ",tab[i].i);
        }
        printf("\n");
    }
    for(int i=0; i<t; i++){
        for(int j=0; j<10; j++){
            printf("%d ",tab[i].cyfra[j]);
        }
        printf("\n");
    }
    return 0;
}