Disclaimer: Make sure you tried enough before checking the solution
Problem: https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/I
#include <iostream> #include <algorithm> #include <iomanip> #include <string> #include <cmath> #include <cstring> using namespace std; int checkVowel(char chr) { return (chr == 'A' || chr == 'a' || chr == 'E' || chr == 'e' || chr == 'U' || chr == 'u' || chr == 'O' || chr == 'o' || chr == 'i' || chr == 'I'); } int countVowels(string str, int index) { if (index == -1) { return ; } return checkVowel(str[index - 1]) + countVowels(str, index - 1); } int main() { string str; getline(cin, str); cout << countVowels(str, str.size()); }
Assiut University Training – Newcomers Solution Recursion