Poj Solution 2584

http://poj.org/problem?id=2584

#include"iostream"
#include"algorithm"
using namespace std;
char *size="SMLXT";
int find( char c )
{
    char *q = size;

    while( *q != c )
        q++;

    return q - size;
}
struct person
{
    int b,e;
}p[20];
bool cmp( person p1, person p2 )
{
    return p1.b < p2.b || ( p1.b == p2.b && p1.e < p2.e );
}
int main()
{
    int i, j, n, s[20];
    char t[15],a,b;
    cin>>t;
    while( cin>>n )
    {
        for( i=0; i<n; i++ )
        {
            cin>>a>>b;
            p[i].b = find( a );
            p[i].e = find( b );
        }
        for( i=0; i<5; i++ )
            cin>>s[i];    
        sort( p, p+n, cmp );

        for( i=0,j=0; j<n; j++  )
        {
            while( i < 5 && ( p[j].b > i || s[i] == 0 ) )
                i++;

            if( i >= 5 || p[j].e < i )
                break;
            s[i]--;
        }
        if( j == n ) cout<<"T-shirts rock!n";
        else cout<<"I'd rather not wear a shirt anyway...n";

        cin>>t;
        cin>>t;
    }

    return 0;
}



											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *