fork(4) download
  1. #include <iostream>
  2. #include <list>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int main()
  8. { int a,b;
  9. while(cin>>a)
  10. { list <int> lista;
  11. while(cin>>b)
  12. {
  13. for(list<int>::iterator i=lista.begin();i!=lista.end();i++)
  14. if(*i==b)i=lista.erase(i); lista.push_front(b);if(cin.peek() == '\n'||cin.peek()==EOF)break;
  15. }
  16. lista.sort();
  17. lista.reverse();
  18. if(lista.size()<a) cout<<'-'<<endl;
  19. else{
  20. list<int>::iterator i=lista.begin();
  21. for(int k=1;k<a;k++)
  22. i++;
  23.  
  24. cout<<*i<<endl;} lista.clear();
  25. }
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 2868KB
stdin
5
2 18 18
7 40 30 40 30 29 40 56 47 23 45 20
1 1
2 2 2 2 2 2 2
1 0 0
2 3 0 3
stdout
-
23
1
-
0
0