목차

  1. 환경
  2. 문제
  3. 접근법
  4. Library
  5. Code
  6. 정리
  7. Link

1. 환경

Editor: Microsoft Visual Studio Code
Compiler: C++20

2. 문제

Link1 BOJ2577

3. 접근법

알고리즘 분류

  • 수학
  • 구현
  • 사칙연산

A, B, C가 모두 1000보다 작으므로 셋을 곱한 값 N은 1e9로 int범위 안이라는 점을 유념한다.
Nint형태에서 10씩 나머지, 나누기 처리를 하여 푸는 방식도 있지만,
조금 더 직관적으로 string형식으로 바꾸어 풀었다.

4. Library

bits/stdc++.h - Link2
(GNU C++ Standard Library Header - X)
(GCC Compiler Header - O)
string - Link3
string - std::to_string - Link4

5. Code

#include <bits/stdc++.h>

using namespace std;

int arr[10];
string str;

void input();
void func();
void output();

int main(void)
{
    input();
    func();
    output();
}

void input()
{
    int A, B, C, N;
    cin >> A;
    cin >> B;
    cin >> C;
    N = A * B * C;
    str = to_string(N);
}

void func()
{
    for(int i = 0; i < str.size(); i++)
        arr[str.at(i) - '0']++;
}

void output()
{
    for(int i = 0; i < 10; i++)
        cout << arr[i] << '\n';
}

6. 정리

뇌피셜이지만 수가 커질수록 int타입으로 처리하는 방식은
연산에 대한 부하가 커질 것이라 생각되어진다.
여러가지 라이브러리를 익혀 잘 써먹을 수 있도록 하자.

1. BOJ2577 - 숫자의 개수
https://www.acmicpc.net/problem/2577
2. bits/stdc++.h
https://gcc.gnu.org/onlinedocs/gcc-4.8.0/libstdc++/api/a01541_source.html
3. string
https://www.cplusplus.com/reference/string/
4. std::to_string
https://www.cplusplus.com/reference/string/to_string/
5. Cplusplus.com
https://www.cplusplus.com/reference/