Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- //б) Простой поиск.
- //Модифицируйте предыдущее задание следующим образом:очередное значение
- //вводится в массив только при условии, что там еще такого нет (то есть
- //дубли игнорируются
- const int NN = 5;
- int Array[NN];
- int x = 0;
- bool not_duplicate = 0;
- for(int i = 0; i<NN; i++)
- {
- std::cout << "enter " << i+1 << " element of Array: "; std::cin >> x;
- int counter = i+1;
- for(int f = 0; f < counter; f++)
- {
- if(!(x==Array[f]))
- {
- not_duplicate = 1;
- }
- else
- {
- not_duplicate = 0;
- }
- }
- if(not_duplicate == true)
- Array[i]=x;
- else
- {
- std::cout << "x is duplicate, try again:"; std::cin >> x;
- }
- for(int j = 0; j<(counter);++j)
- {
- for(int k=j+1; k<(counter); ++k)
- {
- if(Array[k] < Array[j])
- {
- int tmp = Array[j];
- Array[j] = Array[k];
- Array[k]= tmp;
- }
- }
- }
- }
- for(int i = 0; i < NN; i++)
- {std::cout << Array[i] << " ";}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement