Advertisement
Caneq

lb4.1.8(2 способ)

Nov 22nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5. //Для каждого символа заданного текста указать, сколько раз он встречается в тексте.
  6. //Удалить символы, которые встречаются более одного раза.
  7. int main() {
  8.     const int str_len = 100000;
  9.     char str[str_len] = "";
  10.     while (true) {
  11.         cout << "Enter text " << endl;
  12.         cin.getline(str, str_len);
  13.         cout << str << endl;
  14.         int len = 1;
  15.         for (int i = 0; str[i]; len++, i++);
  16.  
  17.         for (int i = 0; i < len; i++) {
  18.             if (!str[i]) {
  19.                 continue;
  20.             }
  21.             char ch = str[i];
  22.             int ch_count = 0;
  23.             for (int j = 0; j < len; j++) {
  24.                 if (str[j] == ch) {
  25.                     ch_count++;
  26.                     if (ch_count > 1) {
  27.                         str[j] = '\0';
  28.                         str[i] = '\0';
  29.                     }
  30.                 }
  31.             }
  32.             cout << ch << " - " << ch_count << endl;
  33.         }
  34.         for (int i = 0; i < len; i++) {
  35.             if (!str[i]) {
  36.                 int j;
  37.                 for (j = i + 1; j < len && !str[j]; j++);
  38.                 str[i] = str[j];
  39.                 str[j] = '\0';
  40.             }
  41.         }
  42.  
  43.         cout << str << endl;
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement