Print the given 3 string after modifying and concatenating

Given three strings(without spaces). The task is to print the new string after modifying the three given string as follows:

  • Replace all the vowels present in the first string with “*”.
  • Don’t change anything in the second string.
  • Replace all the consonants in the third string with “$”.
  • Concatenate all of the three string to obtain the new string.

Examples:

Input : how are you
Output : h*ware$ou

Input : geeks for geeks
Output : g**ksfor$ee$$

The idea is to traverse the first string and keep checking if any character is vowel or not. Replace the character in the first string which is vowel with “*”. Similarly, traverse the third string and keep checking if any character is not a vowel. If a character in the third string is not a vowel(then it is a consonant), replace it with ‘$’.

Finally, concatenate the three strings and print the newly concatenated string.

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to modify the given strings
#include <iostream>
#include <string.h>
using namespace std;
  
// Function to modify the given three strings
string modifyStr(string str1, string str2, string str3)
{
    // Modifying first string
    for (int i = 0; i < str1.length(); i++) {
        if (str1[i] == 'a' || str1[i] == 'e' || 
            str1[i] == 'i' || str1[i] == 'o' || 
            str1[i] == 'u')
            str1[i] = '*';
    }
  
    // Modifying third string
    for (int i = 0; i < str3.length(); i++) {
        if (str3[i] != 'a' && str3[i] != 'e' && 
            str3[i] != 'i' && str3[i] != 'o' && 
            str3[i] != 'u')
            str3[i] = '$';
    }
  
    // Concatenating the three strings
    return (str1 + str2 + str3);
}
  
// Driver code
int main()
{
    string str1 = "how";
    string str2 = "are";
    string str3 = "you";
  
    cout << modifyStr(str1, str2, str3);
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// JAVA program to modify the given Strings
class GFG
{
  
// Function to modify the given three Strings
static String modifyStr(String str1, String str2, String str3)
{
    // Modifying first String
    for (int i = 0; i < str1.length(); i++) {
        if (str1.charAt(i) == 'a' || str1.charAt(i) == 'e' || 
            str1.charAt(i) == 'i' || str1.charAt(i) == 'o' || 
            str1.charAt(i) == 'u')
            str1 = str1.substring(0, i)+ '*'
                   str1.substring(i + 1);
    }
  
    // Modifying third String
    for (int i = 0; i < str3.length(); i++) {
        if (str3.charAt(i) != 'a' && str3.charAt(i) != 'e' && 
            str3.charAt(i) != 'i' && str3.charAt(i) != 'o' && 
            str3.charAt(i) != 'u')
            str3 = str3.substring(0, i)+ '$'
                   str3.substring(i + 1);
    }
  
    // Concatenating the three Strings
    return (str1 + str2 + str3);
}
  
// Driver code
public static void main(String[] args)
{
    String str1 = "how";
    String str2 = "are";
    String str3 = "you";
  
    System.out.print(modifyStr(str1, str2, str3));
}
}
  
// This code is contributed by 29AjayKumar

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to modify the given Strings
  
# Function to modify the given three Strings
def modifyStr(str1, str2, str3):
      
    # Modifying first String
    for i in range(len(str1)):
        if (str1[i] == 'a' or str1[i] == 'e' or
            str1[i] == 'i' or str1[i] == 'o'
            or str1[i] == 'u'):
            str1 = str1[0:i] + '*' + str1[i + 1:];
      
  
    # Modifying third String
    for i in range(len(str3)):
        if (str3[i] != 'a' and str3[i] != 'e' and 
            str3[i] != 'i' and str3[i] != 'o'
            and str3[i] != 'u'):
            str3 = str3[0: i] + '$' + str3[i + 1:];
      
    # Concatenating the three Strings
    return (str1 + str2 + str3);
  
# Driver code
if __name__ == '__main__':
    str1 = "how";
    str2 = "are";
    str3 = "you";
  
    print(modifyStr(str1, str2, str3));
      
# This code is contributed by 29AjayKumar

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to modify the given Strings
using System;
  
class GFG
{
  
// Function to modify the given three Strings
static String modifyStr(String str1, String str2, String str3)
{
    // Modifying first String
    for (int i = 0; i < str1.Length; i++) 
    {
        if (str1[i] == 'a' || str1[i] == 'e' || 
            str1[i] == 'i' || str1[i] == 'o' || 
            str1[i] == 'u')
            str1 = str1.Substring(0, i)+ '*'
                str1.Substring(i + 1);
    }
  
    // Modifying third String
    for (int i = 0; i < str3.Length; i++)
    {
        if (str3[i] != 'a' && str3[i] != 'e' && 
            str3[i] != 'i' && str3[i] != 'o' && 
            str3[i] != 'u')
            str3 = str3.Substring(0, i)+ '$'
                str3.Substring(i + 1);
    }
  
    // Concatenating the three Strings
    return (str1 + str2 + str3);
}
  
// Driver code
public static void Main(String[] args)
{
    String str1 = "how";
    String str2 = "are";
    String str3 = "you";
  
    Console.Write(modifyStr(str1, str2, str3));
}
}
  
// This code is contributed by PrinciRaj1992

chevron_right


Output:

h*ware$ou



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : 29AjayKumar, princiraj1992