알고리즘 예제/C#

[C#] 백준 알고리즘 - 설탕 배달

KimTory 2022. 5. 19. 19:48

문제 : 백준 알고리즘 2839번 문제

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

 

2839번: 설탕 배달

상근이는 요즘 설탕공장에서 설탕을 배달하고 있다. 상근이는 지금 사탕가게에 설탕을 정확하게 N킬로그램을 배달해야 한다. 설탕공장에서 만드는 설탕은 봉지에 담겨져 있다. 봉지는 3킬로그

www.acmicpc.net

 

풀이 : 


// Input
int input = int.Parse(ReadLien()); // 설탕
int count = -1; // 봉지 개수

// Processing
 while (input > 0)
{
    if (input % 5 == 0)
    {
        input -= 5;
        Count++;
    }
    else if (input % 3 == 0)
    {
        input -= 3;
        Count++;
    }
    else if (input > 5)
    {
        input -= 5;
        Count++;
    }
    else
    {
        Count--;
        break;
    }    
}

// Output
WriteLine(Count);

 

'알고리즘 예제 > C#' 카테고리의 다른 글

[C#] 프로그래머스 알고리즘 - 숫자 정렬  (0) 2022.05.19