AtCoder Regular Contest #001 A : センター採点

問題概要

数字の列が与えられるので、出現回数の最大値と最小値を出力する。

acceptされたコード

import std.stdio;
import std.algorithm;

immutable MAX_N = 100;

int N;
char[] buf;

void init(){
	buf = new char[MAX_N + 1];
	scanf("%d %s", &N, buf.ptr);
	buf = buf[0..N];
}

void solve(){
	int ma = 0;
	int mi = int.max;
	foreach( n ; "1234" ){
		ma = max(ma, cast(int)count(buf, n));
		mi = min(mi, cast(int)count(buf, n));
	}
	writeln(ma, " ", mi);
}

void main(){
	init;
	solve;
}