|
|
back to boardStandard Template Library Posted by Madhav 11 Jun 2008 17:19 Standard template library is not available or what? i am getting compilation error for this problem.This is my code <code> #include<iostream> #include<algorithm> using namespace std; class node{ public: int id,prob; bool operator<(const node &n)const{ return (prob>n.prob); } }; int main() { int n; scanf("%d",&n); node arr[n]; for(int i=0;i<n;i++){ scanf("%d%d",&arr[i].id,&arr[i].prob); } sort(arr,arr+n); for(int i=0;i<n;i++) { printf("%d %d\n",arr[i].id,arr[i].prob); } return 0; } </code> Edited by author 11.06.2008 17:19 Re: Standard Template Library just replace sort funcion to stable_sort Re: Standard Template Library Standard template library is not available or what? i am getting compilation error for this problem.This is my code <code> #include<iostream> #include<algorithm> using namespace std; class node{ public: int id,prob; bool operator<(const node &n)const{ return (prob>n.prob); } }; int main() { int n; scanf("%d",&n); node arr[n]; for(int i=0;i<n;i++){ scanf("%d%d",&arr[i].id,&arr[i].prob); } sort(arr,arr+n); for(int i=0;i<n;i++) { printf("%d %d\n",arr[i].id,arr[i].prob); } return 0; } </code> Edited by author 11.06.2008 17:19 1) node arr[n]; << ?? node arr[150000]; 2) If you put node arr[150000]; in main - you'll get stack overflow. Make so: node arr[150000]; int main() { int n; scanf("%d",&n); ... 3) Use stabe_sort instead of sort, or you catch WA#4. After that you'll get AC. http://acm.timus.ru/status.aspx?space=1&count=1&from=3148125 Good luck! |
|
|