Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. //б) Простой поиск.
  6. //Модифицируйте предыдущее задание следующим образом:очередное значение
  7. //вводится в массив только при условии, что там еще такого нет (то есть
  8. //дубли игнорируются
  9. const int NN = 5;
  10.  
  11.  
  12.  
  13. int Array[NN];
  14.  
  15. int x = 0;
  16.  
  17. bool not_duplicate = 0;
  18.  
  19. for(int i = 0; i<NN; i++)
  20. {
  21. std::cout << "enter " << i+1 << " element of Array: "; std::cin >> x;
  22.  
  23. int counter = i+1;
  24.  
  25. for(int f = 0; f < counter; f++)
  26. {
  27.  
  28. if(!(x==Array[f]))
  29. {
  30. not_duplicate = 1;
  31. }
  32. else
  33. {
  34. not_duplicate = 0;
  35. }
  36. }
  37. if(not_duplicate == true)
  38. Array[i]=x;
  39. else
  40. {
  41. std::cout << "x is duplicate, try again:"; std::cin >> x;
  42. }
  43.  
  44. for(int j = 0; j<(counter);++j)
  45. {
  46.  
  47. for(int k=j+1; k<(counter); ++k)
  48. {
  49. if(Array[k] < Array[j])
  50. {
  51. int tmp = Array[j];
  52.  
  53. Array[j] = Array[k];
  54.  
  55. Array[k]= tmp;
  56. }
  57. }
  58.  
  59. }
  60.  
  61.  
  62. }
  63.  
  64.  
  65. for(int i = 0; i < NN; i++)
  66. {std::cout << Array[i] << " ";}
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement