hahn

[백준 - JAVA] 집 주소 본문

코딩테스트 연습/백준(JAVA)

[백준 - JAVA] 집 주소

hahn 2021. 9. 15. 17:16
728x90
반응형

1284번: 집 주소 (acmicpc.net)

 

1284번: 집 주소

재석이는 대문에 붙이는 (주소를 나타내는) 호수판 제작업체의 직원이다. 고객에게 전달할 호수판은 숫자와 숫자 사이 그리고 왼쪽 오른쪽으로 적당히 여백이 들어가 줘야하고 숫자마다 차지하

www.acmicpc.net

더보기
import java.util.Scanner;

class Main{
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
		
		int address = -1,
			result;
		
		while(true) {
			
			address = sc.nextInt();
			
			if(address == 0) break;
			
			result = 1;
			
			while(address != 0) {
				
				if(address % 10 == 1) {
					result += 2;
				}else if(address % 10 == 0) {
					result += 4;
				}else {
					result += 3;
				}
				
				address /= 10;
				
				result++;
				
			}
			
			System.out.println(result);
            
        }
        
    }
    
}

ez

728x90
반응형