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 1140. Swamp Incident

Please help me with my program
Posted by dunno1 17 Dec 2007 00:24
I just can't find where's mistake - i always get WA at test #1:

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n;i>-1;i--)
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>k;i--)
#define PB push_back

using namespace std;


int main()
{
    int n;
    cin>>n;

    int X=0,Y=0,Z=0;

    REP(i,n)
    {
            char a;int p;
            cin>>a;cin>>p;
            if(a=='X') X+=p;
             else if(a=='Y') Y+=p;
              else Z+=p;
    }
    X+=Y;Z+=Y;

    if(X==0&&Z==0) cout<<"0"<<endl;

    else if(X==0) { cout<<"1"<<endl;cout<<"Z: "<<(-1)*Z<<endl;}
    else if(Z==0){ cout<<"1"<<endl; cout<<"X: "<<(-1)*X<<endl;}
    else if(abs(X)==abs(Z)) { cout<<"1"<<endl;cout<<"Y: "<<(-1)*X<<endl;}
  else  if(X>0&&Z>0)
    {
        int minimum=X+Z;
    int a=min(X,Z);

            if(X<Z)
            { cout<<"2"<<endl;
                     cout<<"Y: "<<(-1)*a<<endl;
                     cout<<"Z: "<<(-1)*(Z-a)<<endl;
            }
            else
             { cout<<"2"<<endl;
                     cout<<"X: "<<(-1)*(X-a)<<endl;
                     cout<<"Y: "<<(-1)*a<<endl;
            }
    }
    else if(X<0&&Z<0)
    {
          int minimum=X+Z;
          int a=abs(max(X,Z));
                if(X<Z)
            {
                       cout<<"2"<<endl;
                       cout<<"X: "<<(-1)*(X+a)<<endl;
                     cout<<"Y: "<<a<<endl;
            }
            else
             { cout<<"2"<<endl;
                     cout<<"Y: "<<a<<endl;
                     cout<<"Z: "<<(-1)*(Z+a)<<endl;
            }

    }
    else
    { cout<<"2"<<endl;
             cout<<"X: "<<(-1)*X<<endl;
                     cout<<"Z: "<<(-1)*Z<<endl;
    }

    int p;cin>>p;

}