Posts [BOJ 백준] 1284번 집 주소 / C++
Post
Cancel

[BOJ 백준] 1284번 집 주소 / C++


Contents



문제


문제를 보시려면 링크를 클릭해주세요.


풀이


N이 1일 경우, 0일 경우, 그 외 나머지 숫자일 경우로 나눠서 풀었습니다.

오른쪽, 왼쪽 여백은 반드시 존재하므로 총 sum값에 2를 더해줬습니다.


소스 코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>

using namespace std;

int main(){
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int N;
	
	while(true){
		cin >> N;
		int sum=0;
		
		if(N==0)
			return 0;
			
		while(true){
			if(N%10==1) sum+=2;
			else if(N%10==0) sum+=4;
			else sum+=3;	
			
			if(N<10) break;
			
			N/=10;
			sum+=1;	
		}
		
		cout << sum+2 <<"\n";
	}
	return 0; 
}



This post is licensed under CC BY 4.0 by the author.

[WebLogic] 웹로직 콘솔 /management 경로 막기

[BOJ 백준] 1085번 직사각형에서 탈출 / C++

Comments powered by Disqus.