当前位置:编程学习 > C#/ASP.NET >>

用C#编程:输入一些给定的字符串,统计它们各自出现的次数

补充:就是用C#编程:题目是(输入一些给定的字符串,统计它们出现的次数并且不区分大小写)

追问:麻烦你再跟我解释一下你编这个程序的思路好吗?
答案:好久没有碰问问了。声望值降的都快没有了。所以楼主定要采纳我为满意哦。谢谢哈。

附上答案吧。

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string Str = "AaccdDDeFFeetttee";
            string CapStr = Str.ToUpper();
            List<string> CharTemp = new List<string>();
            for (int i = 0; i < CapStr.Length; i++)
            {
                if (CharTemp.Count == 0)
                {
                    CharTemp.Add(CapStr[i].ToString());
                    continue;
                }
                int count = 0;
                for (int j = 0; j < CharTemp.Count; j++)
                {
                    if (!CapStr[i].ToString().Equals(CharTemp[j].ToString()))
                    {
                        count++;
                    }

                }
                if (count == CharTemp.Count)
                {
                    CharTemp.Add(CapStr[i].ToString());
                }

            }
            Console.WriteLine("在"+Str+"字符串中,不区分大小写的情况下,字符个数如下所示:");
            for (int i = 0; i < CharTemp.Count; i++)
            {
                int total = 0;
                for (int j = 0; j < CapStr.Length; j++)
                {
                    if (CharTemp[i].Equals(CapStr[j].ToString()))
                    {
                        total++;
                    }
                }
                Console.WriteLine(CharTemp[i] + "共有" + total+"个");
            }
            Console.ReadKey();
        }
    }
}
效果图

LZ你描述清楚点

我帮你写

using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            List<String> record = new List<String>()        {            "Hello","World","This","is","my","first","try","to","say","Hello"        };
            var query = from r in record                        group r by r.ToLower() into g                        select new { Count = g.Count(), Value = g.Key };
            foreach (var v in query)            {                Console.WriteLine("Value = {0}, Count = {1}", v.Value, v.Count);            }        }    }}使用LINQ TO OBJECT,一句话就搞定了附上程序#include <iostream>#include <cstdlib>using namespace std;int main(void)unsigned NumDigit(unsigned n);//我相信这个整数不会超过255位吧 unsigned res = 0; itoa(n, c, 10); for (int i = 0; c[i] != NULL; ++i)  res++; return res;}
用C#编程:输入一些给定的字符串,统计它们各自出现的次数这里有视频教程可以看下 http://www.alisoho.com

上一个:用C#编程实现,产生一个1到100之间的随机数的平方以及平方根值
下一个:右下角小图标程序是怎样做出来的。 - C#编程 -

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,