Dev.baelanche

[백준 11006] 남욱이의 닭장 본문

Data Structure & Algorithm/PS - JAVA

[백준 11006] 남욱이의 닭장

baelanche 2019. 4. 19. 21:52
반응형

 

 

주어진 닭의 수 m 에서 2를 곱하면 닭의 다리가 모두 있을때의 개수가 나온다.

 

m*2 - n(다리의 수) 를 하면 다리가 하나인 닭의 수이고 나머지가 멀쩡한 닭의 수 이다.

 

 

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int t = sc.nextInt();
        while(t-->0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int x = m*2 - n;
            System.out.println(x + " " + (m-x));
        }
    }
}
반응형
Comments