Codeforces Round #113 (Div. 2), problem: (A) Rank List editorial: http://codeforces.com/blog/entry/4173
Codeforces Round #113 (Div. 2), problem: (A) Rank List solution: http://ideone.com/iEgAy0
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { int k, n, ans=0; pair <int, int> p[55]; scanf("%d%d", &n, &k); for(int i=0; i<n; i++) scanf("%d%d", &p[i].first, &p[i].second), p[i].first*=-1; sort(p, p+n); for(int i=0; i<n; i++) if(p[i]==p[k-1]) ans++; printf("%d", ans); return 0; }
the above code works fine, but code below does not work, the compiler gives error for "operand[]" but i dont know the exact reason.
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { int k, n, ans=0; pair <int, int> p; scanf("%d%d", &n, &k); for(int i=0; i<n; i++) scanf("%d%d", &p[i].first, &p[i].second), p[i].first*=-1; sort(p, p+n); for(int i=0; i<n; i++) if(p[i]==p[k-1]) ans++; printf("%d", ans); return 0; }
You haven't declared the size of the pair in latter snippet of code.
ReplyDelete