Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int const MAX = 100;
- void InitArray(int* a, int n) {
- for(int i = 0; i < n; i++) {
- std::cin >> a[i];
- }
- }
- void BubbleSort(int* a, int n) {
- for (int i = n - 1; i > 0; i--) {
- for (int j = 0; j < i; j++) {
- if(a[j] > a[j+1]) {
- int tmp = a[j];
- a[j] = a[j+1];
- a[j+1] = tmp;
- }
- }
- }
- }
- void FDupElemInArray(const int* a, int n) {
- int counter = 0;
- int reps = 0;
- for(int i = 0; i < n; i++) {
- if(a[i] == a[i+1]) {
- counter++;
- reps++;
- continue;
- }
- if(reps != 0) {
- std::cout << a[i] << " : " << reps << std::endl;
- }
- reps = 0;
- }
- std::cout << "\nThe number of repetitive elements: " << counte$
- }
- void ShowArray(const int* a, int n) {
- for(int i = 0; i < n; i++) {
- std::cout << a[i] << " ";
- }
- std::cout << "\n\n";
- }
- int main() {
- int arr[MAX] = {0};
- InitArray(arr, MAX); // заполняем массив случайным$
- BubbleSort(arr, MAX); // сортируем массив
- ShowArray(arr, MAX); // выводим отсортированный массив
- FDupElemInArray(arr, MAX); // находим количество всех повторя$
- // и количество повторе$
- std::cin.get();
- std::cin.get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement