Advertisement
fcamuso

C++ 20 - lezione 4

Oct 2nd, 2022
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <format>
  4. #include <string_view>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     string frase = "QuEl ramo del lagO di Como ...";
  12.    
  13.     map<char, int> contatori;
  14.     for (char c : "aeiouAEIOU"sv) contatori.insert(make_pair(c, 0));
  15.  
  16.     int cont_a = 0;
  17.     for(char c: frase)
  18.     {
  19.         switch (const auto it = frase.find("ramo"); c)
  20.         {
  21.             case 'a':
  22.                 cont_a++;
  23.                 [[fallthrough]];
  24.             case 'e':
  25.             case 'i':
  26.             case 'o':
  27.             case 'u':
  28.             case 'A':
  29.             case 'E':
  30.             case 'I':
  31.             case 'O':
  32.             case 'U':
  33.                 contatori[c]++;
  34.        
  35.                 break;
  36.             default:
  37.                 break;
  38.         }
  39.     }
  40.  
  41.     for (auto cont : contatori)
  42.         cout << format("La vocale {} e' stata trovata {} volte.\n", cont.first, cont.second);
  43.  
  44.    
  45.     if (const auto it = frase.find("ramo"); it != string::npos)
  46.         cout << "Trovato ramo \n";
  47.  
  48.  
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement