Advertisement
kirya_shkolnik

Андрей - подсччерт символов -2

Jun 13th, 2021
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. String^ task(String^ str, int& count) {
  2.    
  3.     String^ tempstr = str;
  4.     int maxpos = 0, maxcount = 0;
  5.     Char maxsymbol;
  6.     for (int i = 0; i < str->Length; i++) {
  7.         Char Symbol = str[i];
  8.         int count = 1;
  9.         if (Symbol != ' ' && tempstr->IndexOf(Symbol, i) > -1) { // Если символ не равен пробелу, и такие символы в строке еще есть
  10.             for (int j = i + 1; j < tempstr->Length; j++) {
  11.                 if (tempstr[j] == Symbol) {
  12.                     count++;
  13.                     tempstr = tempstr->Remove(j, 1);
  14.                 }
  15.                 else {
  16.                     break;
  17.                 }
  18.             }
  19.             if (count > maxcount) {
  20.                 maxsymbol = Symbol;
  21.                 maxcount = count;
  22.                 maxpos = i;
  23.             }
  24.         }
  25.     }
  26.     str = str->Remove(maxpos, maxcount+1);
  27.     MessageBox::Show(str, "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error);
  28.     String^ maxstr = maxcount.ToString() + maxsymbol.ToString();
  29.     str = str->Insert(maxpos, maxstr);
  30.     return str;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement