kirya_shkolnik

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

Jun 19th, 2021 (edited)
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include "pch.h"
  2. using namespace System;
  3. using namespace System::Windows::Forms;
  4. #include <string>
  5.  
  6. String^ task(String^ str) {
  7.     int maxpos = 0, maxcount = 0;
  8.     Char maxSymbol;
  9.     for (int i = 0; i < str->Length; i++) {
  10.         Char Symbol = str[i];
  11.         int count = 0;
  12.         int startIndex = i;
  13.         int j = i;
  14.         while (j < str->Length && str[j] == Symbol) {
  15.             count++;
  16.             j++;
  17.         }
  18.         if (count > maxcount) {
  19.             maxSymbol = Symbol;
  20.             maxcount = count;
  21.             maxpos = startIndex;
  22.         }
  23.     }
  24.  
  25.     str = str->Remove(maxpos, maxcount);
  26.     String^ maxstr = maxcount.ToString() + maxSymbol.ToString();
  27.     str = str->Insert(maxpos, maxstr);
  28.     return str;
  29. }
Add Comment
Please, Sign In to add comment