Mam problem z tym zadanie, testy ze spoja wykonuje prawidłowo. Mógłby mi ktoś wskazać błąd w tym kodzie. I jeszcze jedna prośba: Jak zrobić aby program pominął 'y' jeśli jest równy zero, ale pokazał 'x' jeśli jest różny od zera, bo wydaje mi się, że błąd leży w nieuwzględnieniu tych dwóch warunków.
#include <iostream>
#include <cmath>
using namespace std;
int testy;
int main()
{
cin>> testy;
while (testy--)
{
int zestawy;
cin>> zestawy;
int x=0,y=0;
int b;
char a;
for (int i=0;i<zestawy;i++)
{
cin>>a>>b;
if (a=='0')
{
y+=b;
}
else if (a=='1')
{
y-=b;
}
else if (a=='2')
{
x+=b;
}
else
{
x-=b;
}
}
if ((x==0)&&(y==0))
{
cout<< "studnia"<<endl;
}
if (y>0)
{
cout<<'0'<<' '<<y<<endl;
}
else if (y<0)
{
cout<<'1'<<' '<<abs(y)<<endl;
}
if (x>0)
{
cout<<'2'<<' '<<x<<endl;
}
else if (x<0)
{
cout<<'3'<<' '<<abs(x)<<endl;
}
}
return 0;
}