Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
help me...why wa all the time....#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator