Advertisement
cacodemon665

Лаба 4 Вариант 13

Oct 16th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include "pch.h" //для версий вижлы старше последних версий 2017 здесь должно быть #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int k;
  9.  
  10.     cout << "Input k:" << endl;
  11.     cin >> k;
  12.  
  13.     char arr[100000];
  14.  
  15.     cout << "Input array:" << endl;
  16.     for (int i = 0; i < k; i++)
  17.         cin >> arr[i];
  18.  
  19.     int new_size = k;
  20.  
  21.     for (int i = 0; i < new_size; i++)
  22.     {
  23.         for (int j = i + 1; j < new_size; j++)
  24.         {
  25.             if (arr[i] == arr[j])
  26.             {
  27.                 //cout << j << " " << arr[j] << endl;
  28.  
  29.                 for (int k = j + 1; k < new_size; k++)
  30.                 {
  31.                     arr[k - 1] = arr[k];
  32.                 }
  33.  
  34.                 new_size--;
  35.                 j--;
  36.  
  37.                 /*for (int i = 0; i < new_size; i++)
  38.                     cout << arr[i] << " ";
  39.  
  40.                 cout << endl;
  41.                 cout << new_size << endl;
  42.                 cout << "-------------------------" << endl;*/
  43.             }
  44.         }
  45.     }
  46.  
  47.     for (int i = 0; i < new_size; i++)
  48.     {
  49.         cout << arr[i] << " ";
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement