我的TL要求我实现这个:
如果我们将英文字母编号为
a 1
b 2
c 3
d 4
e 5
f 6
g 7
h 8
i 9
j 1
k 2
l 3
m 4
n 5
o 6
p 7
q 8
r 9
s 1
t 2
u 3
v 4
w 5
x 6
y 7
z 8
Run Code Online (Sandbox Code Playgroud)
元音会是
a 1
e 5
i 9
o 6
u 3
Run Code Online (Sandbox Code Playgroud)
用户将输入:
现在我需要显示一个长度字符串:用户输入的字符数.
字符串将有两个部分:
第一部分将具有用户输入的总和的元音.
第二部分是长度[用户输入的字符数 - 根据上面的字符串的前半部分的元音],并且总和将与用户输入的相同.
任何机构都可以为此编写C#代码.我努力尝试但无法弄明白.
任何帮助将不胜感激.
到目前为止,这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace VowelsAndConsonants
{
class Program
{
static void Main(string[] args)
{
//Gather Info from the User
Console.WriteLine("Please Enter Number of Vowels");
string numVowels = Console.ReadLine();
Console.WriteLine("Please Enter the Total");
string total = Console.ReadLine();
Console.WriteLine("Please Enter the Number of Chars");
string numChars = Console.ReadLine();
//Convert the Strings entered by User to int
int inNumVowels = Convert.ToInt16(numVowels);
int intTotal = Convert.ToInt16(total);
int intNumChars = Convert.ToInt16(numChars);
//Populate the Array with all the alphanets
string[,] arr = new string[,] { { "a", "1" }, { "b", "2" }, { "c", "3" }, { "d", "4" }, { "e", "5" }, { "f", "6" }, { "g", "7" }, { "h", "8" }, { "i", "9" }, { "j", "1" }, { "k", "2" }, { "l", "3" }, { "m", "4" }, { "n", "5" }, { "o", "6" }, { "p", "7" }, { "q", "8" }, { "r", "9" }, { "s", "1" }, { "t", "2" }, { "u", "3" }, { "v", "4" }, { "w", "5" }, { "x", "6" }, { "y", "7" }, { "z", "8" } };
string[] resArr= new string[20];// = null;
for (int i = 0; i < intNumChars; i++)
{
//The logic you guys would suggest goes here
resArr[0]=arr[,];
//Display the string
Console.WriteLine("");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
困难的部分不是编写代码.困难的部分是弄清楚解决这个问题的算法是什么.一旦你的算法扎实,把它变成代码就会很简单.
您对算法有何看法?从一些人为的例子开始.例如,假设您获得1/9/2.解决方案是IR.作为一个人,你会如何提出这个解决方案?你能描述一种方法,让你,一个人,总能想出答案吗?
| 归档时间: |
|
| 查看次数: |
407 次 |
| 最近记录: |