去除重复的字符

 
  
  1. static public void DeleteRepeatChar(string s){
  2. Dictionary<char, int> d = new Dictionary<char, int>();
  3. foreach (var c in s){
  4. int num = 0;
  5. if (d.TryGetValue(c, out num)){
  6. d[c] += 1;
  7. Console.WriteLine(c);
  8. }else{
  9. d[c] = 1;
  10. }
  11. }
  12. string strs = "";
  13. foreach (var str in d.Keys){
  14. strs += str;
  15. }
  16. Console.WriteLine(strs);
  17. }
  18. static string AcceptmultiLineChars() {
  19. ConsoleKeyInfo cki;
  20. Console.TreatControlCAsInput = true;//防止Ctrl+C复制
  21. Console.WriteLine("Press the CTRL+Enter key to quit: \n");
  22. string result = string.Empty;
  23. do {
  24. cki = Console.ReadKey();
  25. if (cki.Key == ConsoleKey.Enter) {
  26. result += System.Environment.NewLine;//如果输入回车,则加入换行标志
  27. Console.SetCursorPosition(0, Console.CursorTop + 1);//光标下移一行
  28. }
  29. result += cki.KeyChar;
  30. } while (cki.Key != ConsoleKey.Enter || (cki.Modifiers & ConsoleModifiers.Control) == 0);//按Ctrl+Enter退出
  31. return result;
  32. }
  33. static void Main(string[] args){
  34. string s = AcceptmultiLineChars();
  35. DeleteRepeatChar(s);
  36. }





转载于:https://www.cnblogs.com/xiejunzhao/p/6421995.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值