Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

help me...why wa all the time....

Posted by mudull at 2007-08-10 22:47:51 on Problem 2380
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct sale{
       int qi;
       int si;
       int vi;
};
inline bool compqi(sale a,sale b)   { return a.qi<=b.qi;}
inline bool compsi(sale a,sale b)   { return a.si<=b.si;}
int main()
{
       int n,i,j,q,sum;
       vector<sale> s;
       cin>>n;
       sale p;
       vector<int> itemid;
       vector<int> salepoint;
       while(n)
       {
           scanf("%d%d%d",&p.qi,&p.si,&p.vi);
           
           s.push_back(p);
           n--;
       }
       sort(s.begin(),s.end(),compsi);
       for(i=0;i<s.size()-1;i++)
       {
           if(s[i+1].si==s[i].si) continue;
           salepoint.push_back(s[i].si);                       
       }
       salepoint.push_back(s[i].si);
       sort(s.begin(),s.end(),compqi);
       for(i=0;i<s.size()-1;i++)
       {
           if(s[i+1].qi==s[i].qi) continue;
           itemid.push_back(s[i].qi);                       
       }
       itemid.push_back(s[i].qi);
       printf("%d ",-1);
       for(i=0;i<itemid.size();i++) printf("%d ",itemid[i]);
       printf("\n");
       for(i=0;i<salepoint.size();i++)
       {
            printf("%d ",salepoint[i]);
            q=0;                          
            for(j=0;j<itemid.size();j++)
            {
                 sum=0;
                 for(;itemid[j]==s[q].qi;q++)
                    if(s[q].si==salepoint[i]) sum+=s[q].vi;
                 printf("%d ",sum);                       
            }
            printf("\n");              
       }
       system("pause");
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator