백준 3052 나머지 C++

Kkackit·2022년 1월 1일
0

Beakjoon

목록 보기
20/33

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

개인적으로 재미는 별로 없었던 문제.
특별한 아이디어라기보단
그냥 구조에 구멍없게 잘 짜면 되는 문제 느낌이었다.

근데 좋은 아이디어가 분명 있을텐데 내가 모르는걸지도 모르겠다.

나머지가 나오면 처음 나오면 확인용 배열에 넣어놓고, 대조하면서 결과를 출력하게 했다.
처음 나오는(새로운) 나머지가 나오면 결과 변수에 1씩 더하게 했고..

반복이 끝나면 저장한 결과 변수를 출력해서 마무리.

#include<iostream>
using namespace std;

int main(void)
{
    int input_Array[10];
    int result = 0;

    int check_Array[10];


    for(int i = 0; i < 10; i++)
    {
        cin>>input_Array[i];
        input_Array[i] %= 42;

        check_Array[i] = -1; // 초기화
    }

    int idx = 0;
    bool isCheck = false;
    for(int i = 0; i < 10; i++) //나머지는 결국 1~41
    {
        for(int j = 0; j < idx+1; j++)
        {
            if(input_Array[i] == check_Array[j])
            {
                isCheck = true;
                break;
            }
        }

        if(isCheck == true)
        {
            isCheck = false;            
        }
        else
        {
            
            check_Array[idx] = input_Array[i];
            idx++;
            result++;
        }
        
    }

    cout<<result<<endl;
}

0개의 댓글