ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1014. Product of Digits

Runtime error (Access violation) on test case #40
Posted by Oussama Toujani 1 Mar 2017 19:34
Here's my code :

#include <iostream>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    int tab[9]={0,0,0,0,0,0,0,0,0};
    if (n>=10){
    while(n>=10){
        if (n%9==0){n/=9;tab[8]++;}
        else if (n%8==0){n/=8;tab[7]++;}
        else if (n%7==0){n/=7;tab[6]++;}
        else if (n%6==0){n/=6;tab[5]++;}
        else if (n%5==0){n/=5;tab[4]++;}
        else if (n%4==0){n/=4;tab[3]++;}
        else if (n%3==0){n/=3;tab[2]++;}
        else if (n%2==0){n/=2;tab[1]++;}
        else if(n>9){cout << -1;break;}
    }
    tab[n-1]++;
    if (n<10){
        for(int i(0);i<9;i++){
        for(int j(0);j<tab[i];j++){
        cout << i+1;
        }
        }
    }
    }else {if(n==0)n=10;
    cout <<n;}

    return 0;

}