본문 바로가기
알고리즘/백준 BOJ

[ BOJ/C# ] 2577 숫자의 개수

by 왹져박사 2023. 9. 14.
728x90

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

 

2577번: 숫자의 개수

첫째 줄에 A, 둘째 줄에 B, 셋째 줄에 C가 주어진다. A, B, C는 모두 100보다 크거나 같고, 1,000보다 작은 자연수이다.

www.acmicpc.net

아스키코드를 이용하여 풀었다. 

a*b*c를 string으로 만들어 string은 char의 배열이라는 것을 이용하였다. 

using System;
using System.Text;

namespace B2577
{
    class Program
    {
        static void Main()
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
            StringBuilder sb = new StringBuilder();

            int[] array = new int[3];   //a, b, c
            int[] ints = new int[10];   //1~9

            for(int i = 0; i < array.Length; i++) array[i] = int.Parse(sr.ReadLine());  //a, b, c 저장
            string abc = (array[0] * array[1] * array[2]).ToString();   //abc
            for (int i = 0; i < abc.Length; i++) ints[(int)abc[i] - 48]++;  //아스키코드

            for (int i = 0; i < ints.Length; i++)
            {
                sb.Append(ints[i]);
                sb.Append('\n');
            }
            sw.Write(sb.ToString());
            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

728x90

'알고리즘 > 백준 BOJ' 카테고리의 다른 글

[ BOJ/C# ] 11399 ATM  (0) 2023.09.16
[ BOJ/C# ] 11047 동전 0  (0) 2023.09.15
[ BOJ/C# ] 10818 최소, 최대  (0) 2023.09.13
[ BOJ/C# ] 1929 소수 구하기 _ 에라토스테네스의 체  (0) 2023.09.11
[ BOJ/C# ] 1978 소수 찾기  (0) 2023.09.10