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 1446. Sorting Hat

This is my code with !!!Crash!!!
Posted by Mihr Hovsep 1 Nov 2007 22:50
# include <iostream.h>
# include <string.h>
int main ()
{
    char a[2002][202];
    char b[10000][1000];
    char c[10000][1000];
    char d[10000][1000];
    char e[10000][1000];
    int n,i,j=0,k=0,m=0,h=0;
    cin>>n;
    for (i=0;i<2*n;i++)
        cin.getline (a[i],2002,'\n');
    for (i=0;i<2*n;i=i+2)
    {
        if (a[i+1][0]-'0'=='S'-'0')
        {
            strcpy(b[j],a[i]);
            j++;
        }
        else if (a[i+1][0]-'0'=='H'-'0')
        {
            strcpy(c[k],a[i]);
            k++;
        }
        else if (a[i+1][0]-'0'=='G'-'0')
        {
            strcpy(d[m],a[i]);
            m++;
        }
        else if (a[i+1][0]-'0'=='R'-'0')
        {
            strcpy(e[h],a[i]);
            h++;
        }
    }
    cout<<"Slytherin:"<<endl;;
    for (i=1;i<=j;i++)
        cout<<b[i]<<endl;
    cout<<'\n'<<"Hufflepuff:"<<endl;
    for (i=1;i<=k;i++)
        cout<<c[i]<<endl;
    cout<<'\n'<<"Gryffindor:"<<endl;
    for (i=1;i<=m;i++)
        cout<<d[i]<<endl;
    cout<<'\n'<<"Ravenclaw:"<<endl;
    for (i=1;i<=h;i++)
        cout<<e[i]<<endl;
    return 0;
}





Tell mi what to do,please, and sorry for my English.
Re: This is my code with !!!Crash!!!
Posted by yaho0o0 6 Apr 2009 02:56
your sorce is wronge it is crashing because of
char a[2002][202];
char b[10000][1000];
char c[10000][1000];
char d[10000][1000];
char e[10000][1000];
you got to change to:
char a[103][1002];
char b[102][1002];
char c[102][1002];
char d[102][1002];
char e[102][1002];
but on the first test the program output :
Hufflepuff:

Gryffindor:

Ravenclaw:

the wright answer is :
Slytherin:
Zlobeus Zlei
Um Bridge

Hufflepuff:
Mac Go Nagolo

Gryffindor:
Ivan Ivanov
Garry Potnyj
Herr Mionag-Ranger

Ravenclaw:
Tatiana Henrihovna Grotter