방 번호

https://www.acmicpc.net/problem/1475

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a[9] = {};
int n;
cin >> n;
while (n > 0) {
if (n % 10 == 9) a[6]++;
else a[n % 10]++;
n /= 10;
}
a[6] = (a[6] + 1) / 2;
cout << *max_element(a, a + 9);
return 0;
}
view raw b01475.cpp hosted with ❤ by GitHub
using System;
using System.Linq;
class Program {
public static void Main() {
int[] a = new int[9];
int n = int.Parse(Console.ReadLine());
while (n > 0) {
if (n % 10 == 9) a[6]++;
else a[n % 10]++;
n /= 10;
}
a[6] = (a[6] + 1) / 2;
Console.Write(a.Max());
}
}
view raw b01475.cs hosted with ❤ by GitHub
import java.util.Scanner;
import java.util.Arrays;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] a = new int[9];
int n = sc.nextInt();
while (n > 0) {
if (n % 10 == 9) a[6]++;
else a[n % 10]++;
n /= 10;
}
a[6] = (a[6] + 1) / 2;
System.out.print(Arrays.stream(a).max().getAsInt());
}
}
view raw b01475.java hosted with ❤ by GitHub
a = [0 for _ in range(9)]
n = int(input())
while n > 0:
if n % 10 == 9: a[6] += 1
else: a[n % 10] += 1
n //= 10
a[6] = (a[6] + 1) // 2
print(max(a))
view raw b01475.py hosted with ❤ by GitHub
import java.util.Scanner
fun main() {
val sc = Scanner(System.`in`)
var a = Array<Int>(9) { 0 }
var n = sc.nextInt()
while (n > 0) {
if (n % 10 == 9) a[6]++
else a[n % 10]++
n /= 10
}
a[6] = (a[6] + 1) / 2
a.sortDescending()
print(a[0])
}
view raw b01475.kt hosted with ❤ by GitHub
let a = Array(9).fill(0)
let n = parseInt(require('fs').readFileSync(0))
while (n > 0) {
if (n % 10 == 9) a[6]++
else a[n % 10]++
n = parseInt(n / 10)
}
a[6] = parseInt((a[6] + 1) / 2)
console.log(Math.max(...a))
view raw b01475.js hosted with ❤ by GitHub
import 'dart:io';
import 'dart:math';
void main() {
List<int> l = List.filled(9, 0);
int n = int.parse(stdin.readLineSync()!);
while (n > 0) {
if (n % 10 == 9) l[6]++;
else l[n % 10]++;
n ~/= 10;
}
l[6] = (l[6] + 1) ~/ 2;
print(l.reduce(max));
}
view raw b01475.dart hosted with ❤ by GitHub

풀이

입력값 n을 10으로 나누면서 나머지에 대한 값을 인덱스로 값을 증가해간다.
여기서 9는 6으로 사용할 수 있기 때문에 6에 값을 증가시켜도 상관 없으며
한세트에 6, 9가 두개 들어 있으니 인덱스 6에 대한 값를 반으로 나눈다.