我想以asc顺序在这一行中找到重复的char [英] I want to find the duplicate char in this line in asc order

查看:92
本文介绍了我想以asc顺序在这一行中找到重复的char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在asc命令中找到(打印)此行中的重复字符,仅使用for循环。



例如

string repeatedWord =我想在asc命令中查找此行中的重复字符;



请注意:NO Linq,没有内置方法。



-Update



我已经完成了查找字符串中的字符例如:



I want to find(Print) the duplicate char in this line in asc order using for loop only.

For eg
string repeatedWord = "I want to find the duplicate char in this line in asc order";

Please note that: NO Linq, No inbuilt method.

-Update

I have done to find out the char in a string For eg:

string word = "I want to find the duplicate char in this line in asc order";
string hold = "";
for (int i=0; i< word.Length; i++)
    {
    for(int j=i+1; j< word.Length ; j++)
        {
        
        if(word[i].ToString() == " ")
            {
            break;
            }
        if(word[i] == word[j])
            {
            hold = hold + word[i];
            break;
            }
        
        }
    }

Console.WriteLine(hold);





现在我需要按asc顺序对它进行排序



Now I need to sort it in a asc order

推荐答案

排序。

如果你的功课赢了' t让你使用内置的排序方法,然后写一个快速的冒泡排序 - 这是非常简单的。

然后,循环排序数组比较连续的字符 - 第一次两个匹配,你发现了你正在寻找重复。
Sort it.
If your homework won't let you use the inbuilt sort methods, then write a quick bubble sort - it's pretty trivial.
Then, loop through the sorted array comparing consecutive characters - the first time the two match, you have found the duplicate you are seeking.


我会这样做:

迭代字符串并从字符串中的字符构建一个List(of Char)。在你再次添加之前,你必须查看List allready是否包含Char。

现在你构建另一个List或一个与Character-List对应的数组。

你再次通过String迭代并在该位置(索引)处增加整数数组,该位置对应于Char-List。
I would do it like this :
Iterate through the string and build a List (of Char) from the Characters in the String. Here you must look if the List allready contains the Char before you add it again.
Now you build another List or an Array which corresponds to the Character-List.
You iterate once more through the String and increase the Integer-Array at that Position (Index) which corresponds to the Char-List.


这篇关于我想以asc顺序在这一行中找到重复的char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆