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

why my program 1446 in not working?
Posted by cash 25 Apr 2006 14:09
Can anybody help me?
Why my program is not working?
This is it:

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define bsize 200

int main(){
char **mas1,**mas2,*fak[4]={"Slytherin",
                            "Hufflepuff",
                "Gryffindor",
                "Ravenclaw"};
char buf[bsize],name[20]="";
int n=0,i,j,l=0;
FILE *in;

cin>>name;
in=fopen(name,"rt");
if(in==NULL) return 1;

fgets(buf,199,in);
n=atoi(buf);

if(n>0){
 *mas1=new char[n*2]; for(i=0;i<n*2;i++) mas1[i]=new char[bsize];
 *mas2=new char[n+7]; for(i=0;i<n+7;i++) mas2[i]=new char[bsize];
 n*=2;

 while(!feof(in)){fgets(buf,sizeof(buf),in); strcpy(mas1[l],buf); l++;}
 l=0; fclose(in);

 for(i=0;i<4;i++){
  strcpy(mas2[l],fak[i]);
  l++;

  for(j=1;j<n;j+=2)
   if(strcmp(mas1[j],fak[i])==0)
    {strcpy(mas2[l],mas1[j-1]); l++;}

  mas2[l]="\n"; l++; }

 for(j=0;j<l;j++) cout<<mas2[j]<<endl;

} else fclose(in);
return 0;}