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

Here is my code.Who can tell me my mistake???I got WA on test #1
Posted by Anastas 22 Jun 2007 14:45
Re: Here is my code.Who can tell me my mistake???I got WA on test #1
Posted by Anastas 22 Jun 2007 15:09
#include<iostream.h>
#include<stdio.h>
#include<string.h>
struct Magicman{
    char name[201];
};
int main()
{
    int i,l,n;
    char fac[40];
    int Slyth[1000]={0},Huffl[1000]={0},Gryff[1000]={0},Raven[1000]={0};
    cin>>n;
    Magicman *a;
    a=new Magicman[n+1];
    for(i=1;i<=n;i++){
        gets(a[i].name);
        cin>>fac;
        if(strcmp(fac,"Slytherin")==0)            Slyth[++Slyth[0]]=i;
        if(strcmp(fac,"Hufflepuff")==0)            Huffl[++Huffl[0]]=i;
        if(strcmp(fac,"Gryffindor")==0)            Gryff[++Gryff[0]]=i;
        if(strcmp(fac,"Ravenclaw")==0)            Raven[++Raven[0]]=i;
    }
        cout<<"Slytherin:"<<endl;
        for(i=1;i<=Slyth[0];i++){
            l=strlen(a[Slyth[i]].name);
            a[Slyth[i]].name[l]=NULL;
            cout<<a[Slyth[i]].name<<endl;
        }
        cout<<endl<<"Hufflepuff:"<<endl;
        for(i=1;i<=Huffl[0];i++){
            l=strlen(a[Huffl[i]].name);
            a[Huffl[i]].name[l]=NULL;
            cout<<a[Huffl[i]].name<<endl;
        }
        cout<<endl<<"Gryffindor:"<<endl;
        for(i=1;i<=Gryff[0];i++){
            l=strlen(a[Gryff[i]].name);
            a[Gryff[i]].name[l]=NULL;
            cout<<a[Gryff[i]].name<<endl;
        }
        cout<<endl<<"Ravenclaw:"<<endl;
        for(i=1;i<=Raven[0];i++){
            l=strlen(a[Raven[i]].name);
            a[Raven[i]].name[l]=NULL;
            cout<<a[Raven[i]].name<<endl;
        }
    return 0;
}