Posts [BOJ 백준] 1475번 방 번호 / C++
Post
Cancel

[BOJ 백준] 1475번 방 번호 / C++


Contents



문제


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


풀이


string 타입으로 입력받아, 0~9까지 숫자가 호출된 횟수를 배열에 저장하였습니다.

호출된 횟수 중 가장 큰 값을 출력하면 되는데,

이 때 6, 9는 뒤집어서 사용할 수 있으므로 두 수 호출 횟수/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
34
35
36
37
38
#include <iostream>
#include <vector>
#include<string>

using namespace std;

#define N 10

int main(int argc, char**argv) {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	vector<int> v(N);
	string room_num="";
	int max=0, chk=0;
	
	cin >> room_num;
	
	for(int i=0; i < room_num.size(); i++){
		v[room_num.at(i) -'0']++;
		
		if(room_num.at(i) -'0'==6||room_num.at(i) -'0'==9)
			chk++;	
	}
	
	for(int i=0; i<N; i++){
		if(i!=6 && i!=9 && max<v[i])
			max=v[i];
	}
	
	if(max<(chk+1)/2)
		max=(chk+1)/2;

	cout << max ;
	 
	return 0;
}



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

[WebLogic] 웹로직 HTTP method 제한 방법

[BOJ 백준] 13300번 방 배정 / C++

Comments powered by Disqus.