为什么我的程序在不应该的情况下重复出现?

发布于 2025-02-06 14:35:41 字数 1198 浏览 0 评论 0原文

我的应用程序基本上采用一串字符,并计算出每个字母字符出现多少次。它还忽略了类型的数字。但是,我第二次将同一字母复制。

代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文