[백준] C# : 초콜릿 자르기(2163번)

ssu_hyun·2022년 8월 25일
0

Data Structure & Algorithm

목록 보기
59/67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            // N x M 크기의 초콜릿 쪼개기 최소화 문제

            // 1. 두 정수 N, M 입력받기
            int[] s = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int n = s[0];
            int m = s[1];

            // 2. 가장 최소로 초콜릿을 자를 수 있는 공식
            // (n-1)+(m-1)*n = nm - 1
            Console.WriteLine(n*m - 1);
        }
    }
}

  • Select
    • LINQ 메소드
    • 전체 컬렉션을 탐색하거나 연산해서 원본 그대로 반환

0개의 댓글