为什么我的程序在不应该的情况下重复出现?
我的应用程序基本上采用一串字符,并计算出每个字母字符出现多少次。它还忽略了类型的数字。但是,我第二次将同一字母复制。
代码:
string input = Console.ReadLine().ToUpper();
while (input[0] != 'q') {
int[] counting = new int[26];
Array.Clear(counting, 0, counting.Length);
//string to array conversion
if (input.Length > 0 && input.ToUpper()[0] == 'Q')
return;
string all = ".";
for (int i = 0; i < input.Length; i++) {
bool checking = false;
string number = "";
for (int j = 0; j < input.Length; j++) {
if (input.ToUpper()[i] == input.ToUpper()[j]) {
number += input.ToUpper()[i];
}
}
for (int j = 0; j < all.Length; j++) {
if (input[i] == all[j]) {
checking = true;
}
}
all += input[i];
if (!checking) {
input = Regex.Replace(input, @ "[\d-]", string.Empty);
Console.Write(number[0].ToString() + number.Length.ToString() + " ");
}
}
Console.WriteLine();
input = Console.ReadLine();
它应该仅输出“ A6”,这是第一次成功完成,但第二次停止。
输出:
aAaAaA
A6
aAaAaA
A6 A2
My application basically takes a string of characters and counts how many times each of the alphabetic characters appears. It also ignores numbers being type. But it duplicates the same alphabets second time I input it.
Code:
string input = Console.ReadLine().ToUpper();
while (input[0] != 'q') {
int[] counting = new int[26];
Array.Clear(counting, 0, counting.Length);
//string to array conversion
if (input.Length > 0 && input.ToUpper()[0] == 'Q')
return;
string all = ".";
for (int i = 0; i < input.Length; i++) {
bool checking = false;
string number = "";
for (int j = 0; j < input.Length; j++) {
if (input.ToUpper()[i] == input.ToUpper()[j]) {
number += input.ToUpper()[i];
}
}
for (int j = 0; j < all.Length; j++) {
if (input[i] == all[j]) {
checking = true;
}
}
all += input[i];
if (!checking) {
input = Regex.Replace(input, @ "[\d-]", string.Empty);
Console.Write(number[0].ToString() + number.Length.ToString() + " ");
}
}
Console.WriteLine();
input = Console.ReadLine();
It is supposed to only output "A6" which it did successfully the first time but stops on the second time.
Output:
aAaAaA
A6
aAaAaA
A6 A2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论