English 中文(简体)
粗鲁的短信
原标题:Sort letters in huge string
  • 时间:2012-05-04 19:10:15
  •  标签:
  • sorting

我有16份甲基溴文本文件,其中载有一幅无任何区分的纸张和号码。 摘录:“as81jsa8sm1o1kmka9s93m1l”

是否有一种简单的方式来字母所有特性,而不必书写文字? 我害怕联合材料会在档案中坠毁。

感谢。

最佳回答

如果你知道这幅画只包含信件和号码,你就可以使用一种桶子,取得良好的业绩。

我不肯定你使用什么语言,因此我可以假定你能够照常地读写。 我的解决办法是代号

int[] buckets = int[36]; // 26 for letters, 10 for numbers; assuming only lowercase characters
while(string.hasNext()) {
  char x = next character in string;
  if(x.isAlpha()) {
    buckets[x- a ]++;
  }else {
    buckets[26 + x -  0 ]++
  }

}

印刷分类的插图:

string s = ""; // at the end of the loops, s will contain the sorted string
for(int i =0 ; i < 26; ++i) {
  int y = buckets[i];
  for(int j = 0; j < y; ++j) {
    s+=(y+ a );
  }

}
for(int i =0 ; i < 10; ++i) {
  int y = buckets[i+26];
  for(int j = 0; j < y; ++j) {
    s+=(y+ 0 );
  }

}
问题回答

暂无回答




相关问题
How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I m trying two loops (one nested in the other). Here s the code: int counter=0; // inner counter int counter2=0; // outer ...

Can I Nest OrderBy in .NET?

This doesn t seem to work as I intend. VB.NET: Dim x = Model.Discussions.OrderByDescending(Function(d) d.Messages.OrderByDescending(Function(m) m.Sent).First.Sent) For Each d As Discussion In x ....

sorting elements javascript

I m looking for a way to sort my elements, but it isn t as easy as it sounds. Please let me explain My elements are grouped per 6 elements (thumbnails), each x represents a thumbnail However all ...

热门标签