Advertisement
ovi_salman

Problem No 16

Jul 29th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. //You are given an array of n integers and two integers, a value to be deleted, and occurrence to be deleted. Delete given occurred value in the array.
  2. //Input:
  3. //Inputs are positive integer n followed by n integers and two integers, a value to be deleted, and occurrence to be deleted.
  4. //Output:
  5. //Outputs are array values before and after deletion separated by a newline; array values are separated by spaces.
  6.  
  7.  
  8. #include<iostream>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. int a[100],occ,value,n,temp,hpp=0;
  14. cin>>n;
  15.  
  16. for(int i=0; i<n; i++)
  17. {
  18. cin>>a[i];
  19. }
  20. cout<<endl;
  21.  
  22.  
  23. for(int i=0; i<n; i++)
  24. {
  25. cout<<a[i]<<" ";
  26. }
  27. cout<<endl;
  28. cin>>value>>occ;
  29.  
  30. for(int i=0; i<n; i++)
  31. {
  32. if(a[i]==value){
  33. hpp++;
  34. }
  35. if(hpp==occ){
  36. temp=a[i];
  37. a[i]=a[i+1];
  38. a[i+1]=temp;
  39.  
  40.  
  41. }
  42.  
  43. }
  44.  
  45. for(int i=0; i<n-1; i++)
  46. {
  47. cout<<a[i]<<" ";
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement