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 1178. Akbardin’s Roads

WA#6
Posted by Mihran Hovsepyan {1 kurs of <RAU>} 26 May 2008 00:35
Who can help me?
Why I got WA#6
This is my code
# include <iostream>
using namespace std;
int main ()
{
    int n,i,j,k;
    int x[10002],y[10002],h[10002];
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x[i]>>y[i];
        h[i]=i;
    }
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
        {
            if((x[j]<x[i]) || (x[j]==x[i] && y[j]>y[i]))
            {
                k=x[i];x[i]=x[j];x[j]=k;
                k=y[i];y[i]=y[j];y[j]=k;
                k=h[i];h[i]=h[j];h[j]=k;
            }
        }
    for(i=1;i<=(n/2)+1;i+=2)
        cout<<h[i]<<" "<<h[i+1]<<endl;
    return 0;
}
Re: WA#6
Posted by Mansurov Artur 8 Jul 2008 16:02
problem in output
if you use
    for(...;i+=2)
you have to use
    for(...;i<=n;...)

//like this
for(i=1;i<=n;i+=2)
cout<<h[i]<<" "<<h[i+1]<<endl;