Mam problem z tym zadaniem: http://pl.spoj.pl/problems/PP0506A/. Napisałem program, który działa według mnie dobrze, ale SPOJ go nie akceptuje.
#include <iostream>
#include <string>
using namespace std;
struct punkt
{
string str;
int x,y;
};
int main(int argc, char * argv[])
{
int t,n,a1,a2,b1,b2;
int z=1;
punkt pom;
cin>>t;
while(t)
{
cin>>n;
punkt *p=new punkt[n];
for(int i=0;i<n;i++)
cin>>p[i].str>>p[i].x>>p[i].y;
do
{
z=0;
for(int i=0;i<n-1;i++)
{
a1=p[i].x;
b1=p[i].y;
if(a1<0)
a1*=-1;
if(b1<0)
b1*=-1;
a2=p[i+1].x;
b2=p[i+1].y;
if(a2<0)
a2*=-1;
if(b2<0)
b2*=-1;
if((a1+b1)>(a2+b2))
{
pom.x=p[i+1].x;
pom.y=p[i+1].y;
pom.str=p[i+1].str;
p[i+1].x=p[i].x;
p[i+1].y=p[i].y;
p[i+1].str=p[i].str;
p[i].x=pom.x;
p[i].y=pom.y;
p[i].str=pom.str;
z=1;
}else if((a1+b1)==(a2+b2))
{
if(p[i].str>p[i+1].str)
{
pom.x=p[i+1].x;
pom.y=p[i+1].y;
pom.str=p[i+1].str;
p[i+1].x=p[i].x;
p[i+1].y=p[i].y;
p[i+1].str=p[i].str;
p[i].x=pom.x;
p[i].y=pom.y;
p[i].str=pom.str;
z=1;
}
}
}
}while(z==1);
cout<<endl;
for(int i=0;i<n;i++)
{
cout<<p[i].str<<" "<<p[i].x<<" "<<p[i].y<<endl;
}
cout<<endl;
--t;
delete []p;
}
return 0;
}
Wie ktoś może co trzeba w tym programie poprawić?