#include<iostream> #include<algorithm> using namespace std; int main(){ int n, k, licz_k = 0, temp = 0; cin>>n>>k; licz_k = k; int tab[n]; for(int i = 0; i< n; ++i){ cin>>tab[i]; } sort(&tab[0], &tab[n]); reverse(&tab[0], &tab[n]); temp = tab[k-1]; for(int i = k; i<n; ++i){ if(tab[i] == temp){ licz_k++; }else{ break; } } cout<<licz_k; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<iostream> #include<algorithm> using namespace std; int main(){ int n, k, licz_k = 0, temp = 0; cin>>n>>k; licz_k = k; int tab[n]; for(int i = 0; i< n; ++i){ cin>>tab[i]; } sort(&tab[0], &tab[n]); reverse(&tab[0], &tab[n]); temp = tab[k-1]; for(int i = k; i<n; ++i){ if(tab[i] == temp){ licz_k++; }else{ break; } } cout<<licz_k; return 0; } |