📜  将字符串加密到 Rovarspraket(强盗语言)中

📅  最后修改于: 2022-05-13 01:57:06.470000             🧑  作者: Mango

将字符串加密到 Rovarspraket(强盗语言)中

给定一个字符串,任务是编写一个函数translate() 将文本翻译成“rovarspraket”(瑞典语为“强盗的语言”)。也就是说,将每个辅音加倍,并在两者之间放置一个“o”。
例子:

Input : this is fun
Output : tothohisos isos fofunon
t is consonant then double the consonant and place "o" in between, 
So it becomes "tot" and do this for full string

Input : geeks
Output : gogeekoksos

C++
// C++ implementation to Encrypt a
// string into the rovarspraket (Robber Language)
#include
using namespace std;
 
// Function return translated string
string translate(string a)
{
    // Length of the string
    int len = a.length();
    string res="";
     
// Run till length of string
    for(int i=0; i


Java
// Java implementation to Encrypt a
// String into the rovarspraket (Robber Language)
import java.util.*;
 
class GFG
{
 
// Function return translated String
static String translate(String a)
{
    // Length of the String
    int len = a.length();
    String res = "";
     
    // Run till length of String
    for(int i = 0; i < len; i++)
    {
        // checking if character is vowel,
        // if yes then append it as it is
        if (a.charAt(i) == 'a' || a.charAt(i)== 'e' ||
            a.charAt(i) == 'i' || a.charAt(i) == 'o' ||
            a.charAt(i) == 'u')
        {
            res = res + a.charAt(i);
        }
         
        // if space then append as it is
        else if(a.charAt(i) == ' ')
        {
            res = res +a.charAt(i);
        }
         
        // else double the consonant and
        // put o in between
        else
        {
            res = res + a.charAt(i) + 'o' + a.charAt(i);
        }
    }
     
    // return translated String
    return res;
}
 
// Driver Code
public static void main(String[] args)
{
    String str = "geeks for geeks";
     
    // Calling function
    System.out.println(translate(str));
}
}
 
// This code is contributed by PrinciRaj1992


Python
# Python implementation to Encrypt a
# string into the rovarspraket (Robber Language)
 
def translate(a):
    c=0
    x = ""
     
    # Count length of string
    for i in a:
        c+=1
    for i in range (0, c):
        # If alphabet is vowel, do not change
        if a[i] == 'a' or a[i]== 'e' or a[i] == 'i' or a[i] == 'o' or a[i] == 'u':
            b = a[i]
            x += b
             
        # else double the consonant and put 'O' in between the alphabet
        else if a[i]!=" ":
            b = a[i] +'o' + a[i]
            x += b
             
        # if string has space than put space
        else if a[i] == " ":
            x +=a[i]
     
    # print string
    print(x)
     
s = "geeks for geeks"
translate(s)


C#
// C# implementation to Encrypt a
// String into the rovarspraket (Robber Language)
using System;
     
class GFG
{
 
// Function return translated String
static String translate(String a)
{
    // Length of the String
    int len = a.Length;
    String res = "";
     
    // Run till length of String
    for(int i=0; i


输出:

gogeekoksos foforor gogeekoksos