
Problem
Solution
Submissions
Replace All Vowels in a String
Certification: Basic Level
Accuracy: 87.5%
Submissions: 8
Points: 10
Write a C++ program that replaces all vowels in a given string with a specific character.
Example 1
- Input: string = "Hello World", replacement = '*'
- Output: "H*ll* W*rld"
- Explanation:
- Step 1: Identify all vowels (a, e, i, o, u) in the input string.
- Step 2: Replace each vowel with the replacement character '*'.
- Step 3: Return the modified string.
Example 2
- Input: string = "C++ is fun", replacement = '#'
- Output: "C++ #s f#n"
- Explanation:
- Step 1: Identify all vowels (a, e, i, o, u) in the input string.
- Step 2: Replace each vowel with the replacement character '#'.
- Step 3: Return the modified string.
Constraints
- 1 ≤ len(string) ≤ 10^6
- String contains printable ASCII characters
- Time Complexity: O(n), where n is the length of the string
- Space Complexity: O(n)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Iterate through the string and replace each vowel with the specified character.
- Use a set or string of vowels to check if a character is a vowel.
- Handle both lowercase and uppercase vowels.