반응형

백준 11943번 파일 옮기기 풀이 코드

C | C++ | Java | Python


풀이

사과랑 오렌지도 파일이군요. 옮기는 경우의 수는 두 가지, 즉 사과 A개와 오렌지 D개를 옮기거나 사과 C개와 오렌지 B개를 옮기는 수밖에 없습니다. 둘 중 적은 수를 고르면 됩니다.

코드

#include <stdio.h>
int main(void){
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a + d <= b + c)
        printf("%d", a + d);
    else
        printf("%d", b + c);
    return 0;
}
#include <iostream>
using namespace std;
int main(void){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if (a + d <= b + c)
        cout<<a + d;
    else
        cout<<b + c;
    return 0;
}
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();
        int c = sc.nextInt(), d = sc.nextInt();
        System.out.println(Math.min(a + d, b + c));
    }
}
a, b = map(int, input().split())
c, d = map(int, input().split())

print(min(a+d, b+c))

문제 출처

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

반응형

+ Recent posts