Advertisement
tranerius

Одинаковые символы в строке

Mar 1st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. std::string check(const std::string&str) {
  2.     std::string similar;
  3.     bool have_this_symbol = false;
  4.     for (int i = 0; i < str.size(); i++) {
  5.         for (int l = 0; l < str.size(); l++) {
  6.             if (l == i) {
  7.                 continue;
  8.             }
  9.             if (str[i] == str[l]) {
  10.                 for (int k = 0; k < similar.size(); k++) {
  11.                     if (similar[k] == str[l]) {
  12.                         have_this_symbol = true;
  13.                     }
  14.                 }
  15.                 if (!have_this_symbol) {
  16.                     similar += str[l];
  17.                     similar += " ";
  18.                 }
  19.                 have_this_symbol = false;
  20.             }
  21.         }
  22.     }
  23.     if (similar == "") {
  24.         return "одинаковых символов нет";
  25.     }
  26.     else {
  27.         return similar;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement