首页 > 其他 > 详细

看到笔试题目

时间:2014-11-29 00:10:28      阅读:262      评论:0      收藏:0      [点我收藏+]

给定一个字符串 string str = "问答,是网旗下专业的免费知识问答平台,帮助建设行业从业者解决在学习和工作中遇到的实际问题,让建筑人不再有疑问";

编写一个函数找出字符串中出现最多的字符

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "天工问答,是天工网旗下专业的免费知识问答平台,帮助建设行业从业者解决在学习和工作中遇到的实际问题,让建筑人不再有疑问";
            Dictionary<char, int> dic = new Dictionary<char, int>();
            for (int i = 0; i < str.Length; i++)
            {
                if (!dic.ContainsKey(str[i]))
                {
                    dic[str[i]] = 1;
                }
                else
                {
                    dic[str[i]]++;
                }
                
            }
            int maxvalue = dic.Values.Max();
            foreach (char c in dic.Keys)
            {
                if(dic[c]==maxvalue)
                {
                    Console.WriteLine(c);
                    Console.ReadKey();
            }
            }
            
        }
    }
}

 

看到笔试题目

原文:http://www.cnblogs.com/zhanying/p/4129626.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!