Advertisement
ShaaaD

CodeForces1234B1.cpp

Oct 22nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n, k, res=0;
  6. cin>>n>>k;
  7. unsigned long long int display[k], message[n];
  8.  
  9. for(int i=0; i<n; i++){
  10. cin>>message[i];
  11. }
  12. for(int i=0; i<k; i++){
  13. display[i] = 0;
  14. }
  15.  
  16. for(int i=0; i<n; i++){
  17. int flag = 0;
  18.  
  19. for(int j=0; j<k; j++){
  20. if(display[j] == message[i]){
  21. flag = 1;
  22. break;
  23. }
  24. }
  25.  
  26. if(flag == 0){
  27. for(int j=k-1; j>0; j--){
  28. display[j] = display[j-1];
  29. }
  30. display[0] = message[i];
  31. }
  32. /**for(int j=0; j<k; j++){
  33. cout<<display[j]<<" ";
  34. }
  35. cout<<endl;**/
  36. }
  37.  
  38. for(int i=0; i<k; i++){
  39. if(display[i] != 0){
  40. res++;
  41. }
  42. else{
  43. break;
  44. }
  45. }
  46.  
  47. cout<<res<<endl;
  48.  
  49. for(int i=0; i<res-1; i++){
  50. cout<<display[i]<<" ";
  51. }
  52. cout<<display[res-1];
  53.  
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement