VR引擎程序设计基础—国庆作业

78 阅读1分钟

一、求最大篮球的单词数

image.png

using System;
using System.Diagnostics.CodeAnalysis;

namespace Consoleapp1007homework
{
    class program
    {
            static int getCount(int[] count)
        {
            int[] newC = new int[count.Length];
            for (int i = 0; i < count.Length; i++)
            {
                //如果有一个为0 则里面没有一个完整的balsket
                if (count[i] == 0)
                {
                    return 0;
                }
                //basketball 里面含有两个b、a、l所以要除于2
                else if (i == 0 || i == 1 || i == 2)
                {
                    newC[i] = count[i] / 2;
                }
                else
                {
                    newC[i] = count[i];
                }
            }
            //求里面最小值则为单词basketball存在的数量
            int min = newC.Min();
            return min;
        }

        static void Main(string[] args)
        {
            Console.WriteLine("text=");
            char[] text = Console.ReadLine().ToCharArray();
            char[] usenum = { 'b', 'a', 'l', 's', 'k', 'e', 't', };
            int[] count = new int[usenum.Length];
            for (int i = 0; i < text.Length; i++)
            {
                for (int j = 0; j < usenum.Length; j++)
                {
                    if (text[i] == usenum[j])
                    {
                        count[j] += 1;
                    }
                }
            }
            Console.WriteLine(getCount(count));
        }
    }
}

image.png