1. 程式人生 > >156-練習9和10 迴圈練習和字串與字元的處理

156-練習9和10 迴圈練習和字串與字元的處理

9,財務處的小云老師最近就在考慮一個問題:如果每個老師的工資額都知道,最少需要準備多少張人民幣,才能在給每位老師發工資的時候都不用老師找零呢?
這裡假設老師的工資都是正整數,單位元,人民幣一共有100元、50元、10元、5元、2元和1元六種。

            int num = Convert.ToInt32(Console.ReadLine());
            int count100 = num / 100;
            int remain = num % 100;
            int count50 = remain / 50;
            remain = remain % 50;
            int count10 = remain / 10;
            remain = remain % 10;
            int count5 = remain / 5;
            remain = remain % 5;
            int count2 = remain / 2;
            remain = remain % 2;
            Console.WriteLine("100的準備" + count100);
            Console.WriteLine("50的準備" + count50);
            Console.WriteLine("10的準備" + count10);
            Console.WriteLine("5的準備" + count5);
            Console.WriteLine("2的準備" + count2);
            Console.WriteLine("1的準備" + remain);

10,輸入一個字串,判斷其是否是C#的合法識別符號。

            string str = Console.ReadLine();
            bool isRight = true;
            if ((str[0] >= 'a' && str[0] <= 'z') || (str[0] >= 'A' && str[0] <= 'Z') || str[0] == '_' || str[0] == '@')
            {

            }
            else
            {
                isRight = false;
            }
            for (int i = 1; i < str.Length; i++)
            {
                if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '_' || (str[i] >= '0' && str[i] <= '9'))
                {

                }
                else
                {
                    isRight = false;
                }
            }
            if (isRight == false)
            {
                Console.WriteLine("不是合法識別符號");
            }
            else
            {
                Console.WriteLine("是合法識別符號");
            }
            Console.ReadKey();