๐Ÿ‘ฉ‍๐Ÿ’ปProgramming/Coding Test

[C#] [BOJ#2577] ์ˆซ์ž์˜ ๊ฐœ์ˆ˜

taesooya 2022. 7. 30.

https://www.acmicpc.net/problem/2577

 

2741๋ฒˆ: N ์ฐ๊ธฐ

์ž์—ฐ์ˆ˜ N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ N๊นŒ์ง€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net

 

My Solution

  • length : ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ๊ตฌํ•˜๋Š” ๋ฉ”์„œ๋“œ
  • replace : ๊ธฐ์กด์˜ ๋ฌธ์ž๋ฅผ ๋Œ€์ฒดํ•˜๋Š” ๋ฉ”์„œ๋“œ
  • ToString : String ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());

            string numbers = (a * b * c).ToString();

            for (int i = 0; i < 10; i++)
            {
                ~~Console.WriteLine(numbers.Length - numbers.Replace(i.ToString(), "").Length);~~
            }
        }
    }
}

Solution


using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());

            string numbers = (a * b * c).ToString();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(numbers.Length - numbers.Replace(i.ToString(), "").Length);
            }
        }
    }
}

๋Œ“๊ธ€