ovi_salman

Problem No 13

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