C# 韵母使用array编程
追问:可不可以用别的英文词啊,不设定的。。
追问:可不可以用别的英文词啊,不设定的。。
答案:using System;
using System.Collections.Generic;
using System.Text;
namespace caay
{
class Program
{
static void Main(string[] args)
{
System.Console.Out.WriteLine(process("THIS IS OUR BEST"));
System.Console.Out.WriteLine(process("I HAVE A SECRET"));
System.Console.Out.WriteLine(process("NO BALL WINS"));
System.Console.Out.WriteLine(process("ONE TWO THREE FOUR FIVE"));
System.Console.Out.WriteLine(process("FUN IN THE SUN"));
System.Console.Out.WriteLine(process("THESE PRAWNS ARE"));
System.Console.Out.WriteLine(process("ENORMOUS"));
}
public static String process(String str)
{
String[] words = str.Split(' ');
String result = "";
for (int i = 0; i < words.Length; i++ )
{
result += processWord(words[i]) + " ";
}
return result;
}
public static String processWord(String word)
{
String aeiou = "aeiouAEIOU";
for(int i = 0;i<word.Length;i++)
{
if (aeiou.IndexOf(word[i]) >= 0)
{
if (i == 0)
return word.Substring(i) + word.Substring(0, i) + "WAY";
else
return word.Substring(i) + word.Substring(0, i) + "AY";
};
}
return word;
}
}
}这也需要问?
有现成的方法给你用~~
判断有无韵母自不必说~
输入字符串str
检查开头字母str[0]
有韵母 那就 +“WAY”
没有韵母
{
temp = str[0];
for循环str[i] = str[i+1]; // 把第二位以后的字符前移,i 从0 自增到 str.length-2(不解释)
str[str.length-1] = temp; // 首位值传给 str最后一位 ~
}
然后 +“AY”