|
|
back to boardWA #4 my code is here Posted by Jerry 18 Aug 2007 09:31 #include<iostream> #include<algorithm> using namespace std; int used[500000]={0}; bool cmp(int a,int b) { return (a>b); } int main (void) { int N; cin>>N; for (int k=0;k<N;k++) { int f; cin>>f; used[f]++; } sort (used,used+500000,cmp); cout<<used[0]<<endl; return 0; } WA#7 After fixed Posted by Jerry 18 Aug 2007 09:36 WA#7 After fixed #include<iostream> #include<algorithm> using namespace std; struct note { int value; int rank; }; note used[500000]={0}; bool cmp(note a,note b) { return (a.rank>b.rank); } int main (void) { int N,j=0; cin>>N; for (int k=0;k<N;k++) { bool zepo=false; int f; cin>>f; for (int i=0;i<j;i++) if (used[i].value==f) { used[i].rank++; zepo=true; } if (!zepo) { used[j].value=f; used[j].rank=1; } } sort (used,used+j,cmp); cout<<used[0].value<<endl; //cin>>j; return 0; } Re: WA#7 After fixed It's so big...Just create a dynamic array,sort it by sort() function and output n/2-th element of array.Good luck! Edited by author 18.08.2007 14:02 |
|
|