
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ code to find answers by vowel checking
Suppose we have a string S. Amal and Bimal are playing a game. The rules of the game are like: Those who play for the first time, that is Amal is the detective, he should investigate a "crime" and find out the cause. He can ask any questions whose answers will be either "Yes" or "No". If the question’s last letter is a vowel, they answer "Yes" otherwise "No". Here the vowels are: A, E, I, O, U, Y. We have S as question and we have to find the answer.
So, if the input is like S = "Is it in university?", then the output will be Yes.
Steps
To solve this, we will follow these steps −
s := "AEIOUYaeiouy" for initialize i := 0, when i < size of S, update (increase i by 1), do: t := S[i] if t is alphabetic, then: ans := t if ans is in s, then: return "YES" Otherwise return "NO"
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; string solve(string S){ string s = "AEIOUYaeiouy"; char ans; for (int i = 0; i < S.size(); i++){ char t = S[i]; if (isalpha(t)) ans = t; } if (s.find(ans) != -1) return "YES"; else return "NO"; } int main(){ string S = "Is it in university?"; cout << solve(S) << endl; }
Input
"Is it in university?"
Output
YES
- Related Articles
- C++ code to find corrected text after double vowel removal
- Checking HTTP Status Code in Selenium.
- Python program to find happiness by checking participation of elements into sets
- C++ code to find minimum jump to reach home by frog
- Checking active process in SAP system and which code is running
- C++ code to find total time to pull the box by rabbit
- Java program to find whether given character is vowel or consonant
- C++ code to find the area taken by boxes in a container
- Program to find if a character is vowel or Consonant in C++
- Program to find length of longest substring with even vowel counts in Python
- Removing last vowel - JavaScript
- Java program to find whether given character is vowel or consonant using switch case
- Divisibility by which number is understood by checking the last two digits?
- Numbers obtained during checking divisibility by 7 using JavaScript
- Distance to nearest vowel in a string - JavaScript

Advertisements