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 1028. Stars

wrong answer
Posted by CS03 31 Jul 2012 04:30
why my program give wrong answer?

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <sstream>
using namespace std;
struct RPair
{
    int x;
    int y;
};
int main()
{
    int N;
    while(cin>>N)
    {
       int p1,p2;
       RPair P;
       vector<int> x_hold;
       vector<int> y_hold;
       vector<RPair> P_hold;
          string  stringx_hold;
           string stringy_hold;
       vector<int> level;
       level.resize(N);
       ostringstream convert;
       string result;
        for(int i=0;i<N;i++)
        {
            cin>>p1>>p2;
              x_hold.push_back(p1);
              y_hold.push_back(p2);
              P.x=p1;P.y=p2;
              P_hold.push_back(P);
              convert<<p1;
              result=convert.str();
              stringx_hold+=result[result.size()-1];
             convert<<p2;
              result=convert.str();
              stringy_hold+=result[result.size()-1];
        }
    sort(x_hold.begin(),x_hold.end());
    sort(y_hold.begin(),y_hold.end());
    sort(stringx_hold.begin(),stringx_hold.end());
    sort(stringy_hold.begin(),stringy_hold.end());
    for(int i=0;i<P_hold.size();i++)
    {
        RPair temp;
        for(int j=0;j<P_hold.size();j++)
        {
            if(P_hold[i].x<P_hold[j].x)
            {
               temp=P_hold[i];
               P_hold[i]=P_hold[j];
               P_hold[j]=temp;
            }
            if(P_hold[i].x==P_hold[j].x&&P_hold[i].y<P_hold[j].y)
            {
               temp=P_hold[i];
               P_hold[i]=P_hold[j];
               P_hold[j]=temp;
            }
        }
    }
    size_t found;
    int t=0;
    for(int i=0;i<x_hold.size();i++)
    {
        t=i;
        if(i!=x_hold.size()-1)
        {
            while(P_hold[t].x==P_hold[t+1].x&&P_hold[t].y==P_hold[t+1].y)
            {
                t++;
              if(t==x_hold.size()-1)
                  break;
            }
        }
        if(i==t)
        {
        convert<<P_hold[t].y;
        result=convert.str();
        found=stringy_hold.find(result[result.size()-1]);
        level[min((int)found,t)]++;
        //stringy_hold.insert((int)found,"n");
        stringy_hold.replace((int)found,1,"n");
        }
        else
        {
     int hold=  level[t]++;
        //stringy_hold.insert((int)found,"n");
        stringy_hold.replace(t,1,"n");
        for(int j=i;j<t;j++)
        {
            level[t]++;
             stringy_hold.replace(j,1,"n");
        }
        }
        i=t;
    }
     for(int i=0;i<level.size();i++)
         cout<<level[i]<<"\n";
     }
}