fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long i,n,k,x,j,m;
  5. long long a[1000];
  6. long long b[1000];
  7.  
  8. void cau1()
  9. {
  10. m=0;
  11. for(int i=1;i<=n;i++)
  12. {
  13. if(a[i]%2==0)
  14. {
  15. m++;
  16. b[m]=a[i];
  17. }
  18. }
  19. }
  20.  
  21. void cau2()
  22. {
  23. for (i=k;i<=m-1;i++) b[i]=b[i+1];
  24. m--;
  25. }
  26.  
  27. void cau3()
  28. {
  29. m++;
  30. for(int i=m;i>=2;i--) b[i]=b[i-1];
  31. b[1]=x;
  32.  
  33. }
  34.  
  35. void cau4()
  36. {
  37. int t=b[1];
  38. for(int i=1;i<=m-1;i++) b[i]=b[i+1];
  39. b[m]=t;
  40. }
  41.  
  42. void nhap()
  43. {
  44. cin>>n>>k>>x;
  45. for (int i=1;i<=n;i++) cin>>a[i];
  46. }
  47.  
  48. void xuat_mang_b()
  49. {
  50. for (int i=1;i<=m;i++)
  51. cout<<b[i]<<" ";
  52. cout<<endl;
  53. }
  54.  
  55. void xuli()
  56. {
  57. cau1();
  58. xuat_mang_b();
  59. cau2();
  60. xuat_mang_b();
  61. cau3();
  62. xuat_mang_b();
  63. cau4();
  64. xuat_mang_b();
  65.  
  66. }
  67. int main()
  68. {
  69. nhap();
  70. xuli();
  71. }
  72.  
Success #stdin #stdout 0s 5316KB
stdin
7 3 3
4 2 3 3 5 10 2
stdout
4 2 10 2 
4 2 2 
3 4 2 2 
4 2 2 3