也许你是一个老实的人,没有谈过朋友,也许你是一个花花公子,追过很多女孩子,也被许多女孩子追过,总之你的一生就像是一个很长很长的字符串,每一个字符代表在你的人生中出现过的女孩子,到你快要离开人世的时候,你在回想,每个女孩你追过多少次呢,现在就帮你解答:
一:正则求解
 static void Main(string[] args)
static void Main(string[] args) {
        { ArrayList list = new ArrayList();
            ArrayList list = new ArrayList(); Console.WriteLine("Please input a string");
            Console.WriteLine("Please input a string"); string appearWord="";
            string appearWord=""; string test = Console.ReadLine();
            string test = Console.ReadLine(); char[] c = test.ToCharArray();
            char[] c = test.ToCharArray(); foreach (char cc in c)
            foreach (char cc in c) {
            { if(!list.Contains(cc.ToString()))
                if(!list.Contains(cc.ToString())) {
                { list.Add(cc.ToString());
                    list.Add(cc.ToString()); }
                } }
            } list.Sort();
            list.Sort(); for(int i=0;i<list.Count;i++)
            for(int i=0;i<list.Count;i++) {
            { appearWord+=list[i].ToString();
                appearWord+=list[i].ToString(); }
            } Console.WriteLine("You input a string just:{0}", test);
            Console.WriteLine("You input a string just:{0}", test); Console.WriteLine("你刚输入的字符串中一共有{0},字符出现,它们是:{1}", list.Count, appearWord);
            Console.WriteLine("你刚输入的字符串中一共有{0},字符出现,它们是:{1}", list.Count, appearWord); for (int j = 0; j < list.Count; j++)
            for (int j = 0; j < list.Count; j++) {
            { Console.WriteLine("{0}出现的次数是:{1}", list[j].ToString(), returnAppareNum(test, list[j].ToString()));
                Console.WriteLine("{0}出现的次数是:{1}", list[j].ToString(), returnAppareNum(test, list[j].ToString())); }
            } Console.Read();
            Console.Read(); }
        } //一个字符或者字符串在另一个字符串出现的次数
        //一个字符或者字符串在另一个字符串出现的次数 static int returnAppareNum(string source, string patten)
        static int returnAppareNum(string source, string patten) {
        { MatchCollection mc = Regex.Matches(source, patten);
            MatchCollection mc = Regex.Matches(source, patten); return mc.Count;
            return mc.Count; }
        }二:递归求解
 static void Main(string[] args)
static void Main(string[] args) {
        { string test = "ubaadfasd";
            string test = "ubaadfasd"; abc(test);
            abc(test); Console.Read();
            Console.Read(); }
        } public static void abc(string source)
        public static void abc(string source) {
        { string aaa = "";
            string aaa = ""; if (source.Length > 0)
            if (source.Length > 0) {
            { string a = source.Substring(0, 1);
                string a = source.Substring(0, 1); Console.WriteLine("{0}出现{1}次",a,ab(source, a));
                Console.WriteLine("{0}出现{1}次",a,ab(source, a)); aaa=source.Replace(a, "");
                aaa=source.Replace(a, ""); abc(aaa);
                abc(aaa); }
            } }
        } public static int ab(string dd, string aad)
        public static int ab(string dd, string aad) {
        { int num = 0;
            int num = 0; char[] c = dd.ToCharArray();
            char[] c = dd.ToCharArray(); for (int i = 0; i < c.Length; i++)
            for (int i = 0; i < c.Length; i++) {
            { if (c[i].ToString().Equals((object)aad))
                if (c[i].ToString().Equals((object)aad)) {
                { num += 1;
                    num += 1; }
                } }
            } return num;
            return num; }
        } 
                    
                 

 
        
 
             
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号