浙江大学PAT---Basic Level---1006----换个格式输出整数

题目:http://pat.zju.edu.cn/contests/pat-b-practise/1006

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

namespace PAT_1006
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入数字:");
            int input_num;
            input_num = Int32.Parse(Console.ReadLine());

            int B_num=0, S_num=0, G=0;

            if (input_num < 1000)
            {
                B_num = (int)(input_num / 100);
                input_num = (int)(input_num % 100);
                S_num = (int)(input_num / 10);
                G = (int)(input_num % 10);
                PrintBSG(B_num, S_num, G);
            }
            else return;
            Console.ReadKey();
        }

        private static void PrintBSG(int B_num, int S_num, int G)
        {
            for (int i = 0; i < B_num; i++)
            {
                Console.Write("B");
            }
            for (int i = 0; i < S_num; i++)
            {
                Console.Write("S");
            }
            for (int i = 1; i <= G; i++)
            {
                Console.Write(i);
            }
        }
    }
}


你可能感兴趣的:(浙江大学PAT---Basic Level---1006----换个格式输出整数)