81. 콘솔에서 세 개의 정수( r, g, b )를 입력받고 세 수의 조합을 출력하고, 조합의 수를 출력하라.

입력 범위 : 0 ~ 128

출력:

0 ~ r-1, 0 ~ g-1, 0 ~ b-1 까지의 수의 조합을 모두 출력하고, 조합의 수를 출력

단, 출력할때는 오름차순으로 출력한다.

입력 예시

2 2 2

출력 예시

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

8

JAVA

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int rColorMax = scan.nextInt();
		int gColorMax = scan.nextInt();
		int bColorMax = scan.nextInt();
		scan.close();
		
		int count = 0;
		for (int r = 0; r < rColorMax; r++) {
			for (int g = 0; g < gColorMax; g++) {
				for (int b = 0; b < bColorMax; b++) {
					System.out.println(r + " " + g + " " + b);
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Swift 4.2

import Foundation

if let line = readLine(){
    let valueArray = line.split(separator: " ")
    if valueArray.count == 3,
        let rColorMax = Int(valueArray.first!),
        let gColorMax = Int(valueArray[1]),
        let bColorMax = Int(valueArray[2])
    {
        var count = 0
        for r in 0 ..< rColorMax {
            for g in 0 ..< gColorMax {
                for b in 0 ..< bColorMax {
                    print("\(r) \(g) \(b)")
                    count += 1
                }//for:bColor
            }//for:gColor
        }//for:rColor
        print(count)
    }
}

이전 1081항 문제소스에서 살짝 수정했습니다.

https://codeup.kr/problem.php?id=1084

 

 

+ Recent posts