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 1095. Nikifor 3

WA 4# Please help
Posted by Marck 20 Sep 2009 01:41
I really don't like to do it, but i just can't find what is wrong in my code... In my pc it works pretty fine.. but, i got WA 4#...

my bugged code:

==========================================================

#include <iostream>

using namespace std;

void reordena(int *numeros[],int difzero,int num)
{
    int rdn1,rdn2,aux;

    rdn1 = rand() % difzero;
    rdn2 = rand() % difzero;

    aux = numeros[num][rdn1];
    numeros[num][rdn1] = numeros[num][rdn2];
    numeros[num][rdn2] = aux;
}

void permuta(int *numeros[],int num,int tam)
{
    int cont,cont2,aux,difzero=0,resp=0;
    int mult;
    long int contador=0;

    for(cont=0;cont<tam-1;cont++)
    {
        for(cont2=0;cont2<tam-1;cont2++)
        {
            if(numeros[num][cont2]==0)
            {
                aux = numeros[num][cont2];
                numeros[num][cont2] = numeros[num][cont2+1];
                numeros[num][cont2+1] = aux;
            }
        }
    }

    for(cont=0;cont<tam;cont++)
    {
        if(numeros[num][cont]!=0) difzero++;
    }

    mult=1;
    for(cont=difzero-1;cont>=0;cont--)
    {
        aux=(numeros[num][cont]*mult);
        resp+=aux;
        mult*=10;
    }

    while(resp%7!=0)
    {
        reordena(numeros,difzero,num);
        mult=1;
        resp=0;
        for(cont=difzero-1;cont>=0;cont--)
        {
            aux=(numeros[num][cont]*mult);
            resp+=aux;
            mult*=10;
        }
        contador++;
        if(contador>=1000000)
        {
            numeros[num][0]=0;
            resp=0;
        }
    }

}


int main()
{
    int N,cont,**numeros,*tam;
    char aux[200];

    cin >> N;

    if(N<0) exit(0);
    if(N>10000) exit(0);

    tam = new int[N];
    numeros = new int*[N];
    for(cont=0;cont<N;cont++)
    {
        numeros[cont] = new int[20];
    }

    for(cont=0;cont<N;cont++)
    {
        cin >> aux;
        tam[cont] = strlen(aux);
        if(tam[cont]>20)
        {
            exit(0);
        }

        for(int cont2=0;cont2<tam[cont];cont2++)
        {
            numeros[cont][cont2]=aux[cont2]-'0';
        }

        permuta(numeros,cont,tam[cont]);
    }

    system("cls");
    for(cont=0;cont<N;cont++)
    {
        for(int cont2=0;cont2<tam[cont];cont2++)
        {
            if(numeros[cont][0]==0)
            {
                if(cont2==0) cout << "0";
            }
            else if(numeros[cont][cont2]!=0) cout << numeros[cont][cont2];
        }
        if(cont!=N-1) cout << endl;
    }


    delete [] numeros;
    delete [] tam;

    return 0;
}

========================================================

please, help if you can =/
Re: WA 4# Please help
Posted by Ras Misha [t4ce] 10 Jan 2010 19:32
May be late=) but

if input data contain 0
all zeroes must be output
for example

input:
1
12300134

example output:
13124300