C#程序帮助 [英] C# Help with program
问题描述
你好,
我需要为学校创建一个程序.用户输入不包含数字1和0的7位数字(电话号码).每个数字2-9与三个字母相关联,2 =(a,b,c)3 =(d,e,f)等.我需要列出txt文件中所有可能的字母组合(2,147或3 ^ 7). 我可以转换用户输入< string>到charArray,但是我不确定如何给数字"2"赋予(a,b,c)的值,或给"3"赋予(d,e或f ).任何帮助,链接,想法或其他任何东西都将是很大的帮助.
入门方面的帮助很大,我创建了数组数组,将用户输入的字符串转换为数组数组.现在,我需要列出所有可能的字母组合,而不是abc,def,ghi或abcdefghi,我需要更多类似adg,adh,adi,aeg,aeh,aei,afg,afh,afi等的东西.有什么想法吗?感谢
Hello,
I need to create a program for school. User inputs 7 digit number (phone number) without numbers 1 and 0. Each number 2-9 is associated with three letters, 2=(a,b,c) 3=(d,e,f) etc. I need to list all possible letter combinations (2,147 or 3^7) in a txt file. I can convert the user input<string> to a charArray, but I''m not sure how to go about give the number ''2'' the value of (a,b,c), or ''3'' a value of (d,e,or f). Any help, links, ideas, or anything would be a big help.
Big help getting me started, I have created array of arrays, converted user input string into array of arrays. Now I need to list all possible letter combos, instead of abc, def, g or abcdefg I need something more like adg, adh, adi, aeg, aeh, aei, afg, afh, afi, etc. Any ideas? thanks
推荐答案
设置字符数组:
Set up an array of arrays of characters:
char[][] convert = new char[10][];
convert[0] = new char[0];
convert[1] = new char[0];
convert[2] = new char[] { 'A', 'B', 'C' };
...
然后可以将用户输入用作数组的索引.在这里,我使用一个for循环来遍历所有这些,这将为您提供想法:
You can then use the user input as an index into the array. Here I use a for loop to run through them all, which will give you the idea:
for (int i = 0; i < convert.Length; i++)
{
Console.WriteLine();
foreach (char c in convert[i])
{
Console.Write(c);
}
}
我终于得到了想要的输出,感谢格里夫(Griff)的大力帮助,如果有人知道更好的方法,我想看看
这将以7个char数组或3个char数组输出所有可能的组合:
I finally got the output I was looking for, thanks Griff big help getting started, if anyone knows better way, I''d like to see
This outputs every possible combination in a seven char array or 3 char arrays:
for (int i = 0; i < 2188; i++ )
{
writeit.Write(phoneArray[0][d1]);
writeit.Write(phoneArray[1][d2]);
writeit.Write(phoneArray[2][d3]);
writeit.Write(phoneArray[3][d4]);
writeit.Write(phoneArray[4][d5]);
writeit.Write(phoneArray[5][d6]);
writeit.WriteLine(phoneArray[6][d7]);
d1++;
if (d1 > 2)
{
d1 = 0;
d2++;
}
if (d2 > 2)
{
d2 = 0;
d3++;
}
if (d3 > 2)
{
d3 = 0;
d4++;
}
if (d4 > 2)
{
d4 = 0;
d5++;
}
if (d5 > 2)
{
d5 = 0;
d6++;
}
if (d6 > 2)
{
d6 = 0;
d7++;
}
if (d7 > 2)
{
d7 = 0;
writeit.Close();
}
这篇关于C#程序帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!