ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1446. Sorting Hat

WA #1 C++
Posted by Panzer 12 Dec 2010 01:00

Code:

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
int n;

scanf("%d", &n);

string *tab = new string [n*2];

//-------------------INPUT------------------------

for(int i=0; i<n*2; i++){
getline(cin, tab[i]);
}

string *list = new string [n+7];

//------------------Slytherin-----------------------
int pos=0;  //pos - position
list[pos]="Slytherin:";

for(int i=0; i<n*2; i+=2){
if(tab[i+1][0]=='S'){
pos++;
list[pos]=tab[i];
}
}
pos++;
//------------------Hufflepuff-----------------------
pos++;
list[pos]="Hufflepuff:";

for(int i=0; i<n*2; i+=2){
if(tab[i+1][0]=='H'){
pos++;
list[pos]=tab[i];
}
}
pos++;
//------------------Gryffindor-----------------------
pos++;
list[pos]="Gryffindor:";

for(int i=0; i<n*2; i+=2){
if(tab[i+1][0]=='G'){
pos++;
list[pos]=tab[i];
}
}
pos++;
//------------------Ravenclaw-----------------------
pos++;
list[pos]="Ravenclaw:";

for(int i=0; i<n*2; i+=2){
if(tab[i+1][0]=='R'){
pos++;
list[pos]=tab[i];
}
}

//-------------------OUTPUT---------------------------

for(int i=0; i<n+7; i++){
cout << list[i] << endl;
}

delete [] tab;
delete [] list;

system("pause");
return EXIT_SUCCESS;
}