Poj Solution 2563

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

#include<iostream>
using namespace std;
int d=0,m=0;

inline void data(long g)
{cout<<g/10000<<"-";
g%=10000;if(g/1000==0)cout<<'0';
cout<<g/100<<"-";
g%=100;if(g/10==0)cout<<'0';
cout<<g<<' ';

}
inline void demerit()
{cout<<d<<" demerit point(s)."<<endl;}
inline void merit()
{cout<<m<<" merit point(s)."<<endl;}
inline void none()
{cout<<"No merit or demerit points."<<endl;}


int main()
{int k,key=0;
long g,a;
cin>>g;data(g);none();
while(m<5||key<1)
    {if(!key)cin>>a;if(cin.fail()){key=1;a=999999999;}
          do{
            g+=10000;
            if(a>=g&&d){data(g);if(d/2<d-2)d=d/2;else d=d-2;if(d<=0){d=0;none();}else demerit();}
            else {g+=10000;
                    if(a>=g&&m>=0){data(g);m++;merit();}
            }
    
            }while(a>g&&m<5);    

    if(!key){g=a;cin>>k;d+=k;data(g);
          if(d>2*m){d-=2*m;m=0;demerit();}
          else if(d<2*m){m=(m*2-d)/2;d=0;if(m)merit();else none();}
          else {m=0;d=0;none();}
            }
          
}
return 1;
}    
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

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