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

It crashes on test 1, but on my machine, everything is OK
Posted by Grigory 'stargazer' Javadyan [RAU] 21 Feb 2007 17:15
#include <iostream.h>
#include <stdio.h>
#include <string.h>
int p[4]={-1,-1,-1,-1};
struct student
{
    char name [256];
};
int getfac(char* fn);
int main ()
{
    int n,i,j,id;
    struct student stud[4][1000];
    char* fc[4]={"Slytherin","Hufflepuff","Gryffindor","Ravenclaw"};
    char tmp1[256];
    char tmp2[256];
    scanf("%i", &n);
    for(i=0;i<n;i++)
    {
        //scanf("%s\n%s\n",tmp1,tmp2);
        //printf("%s\t-\t%s",tmp1,tmp2);
        cin.getline(tmp1,256);

        //cout<<tmp1<<endl;
        cin.getline(tmp2,256);
        //cout<<tmp2<<endl;
        id=getfac(tmp2);
        strcpy(stud[id][p[id]].name,tmp1);


    }
    for(i=0;i<4;i++)
    {
        if(p[i]>-1)
            cout<<fc[i]<<":\n";
        for(j=0;j<p[i]+1;j++)
        {
            cout<<stud[i][j].name<<"\n";
        }
        cout<<"\n";
    }
    /*char x[256];
    cin.getline (x,256);
    cout<<x<<endl;*/
    return 0;
}

int getfac(char* fn)
{
    if(!strcmp(fn, "Slytherin"))
    {
        p[0]++;
        return 0;
    }
        if(!strcmp(fn, "Hufflepuff"))
    {
        p[1]++;
        return 1;
    }
        if(!strcmp(fn, "Gryffindor"))
    {
        p[2]++;
        return 2;
    }
            if(!strcmp(fn, "Ravenclaw"))
    {
        p[3]++;
        return 3;
    }
    return -1;
}