Advertisement
buonaseva_fatelo

35_pag180

Feb 10th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     char str[100];
  8.     cout << "Inserisci una stringa: ";
  9.     cin.getline(str, 20);
  10.  
  11.     int count[256] = {0}, maxCount = 0;
  12.     char maxChar;
  13.  
  14.     for(int i = 0; i < strlen(str); i++) {
  15.         count[str[i]]++;
  16.         if(count[str[i]] > maxCount) {
  17.             maxCount = count[str[i]];
  18.             maxChar = str[i];
  19.         }
  20.     }
  21.  
  22.     cout << "Il carattere che si ripete di più è '" << maxChar
  23.          << "' con " << maxCount << " ripetizioni." << endl;
  24.  
  25.     return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement