ネタ元 → 0から1000までの0の数を数える / 前フリチックにGo-Lang、片桐風味を添えて、~その3~
んではハッタリ臭のぷんぷんするヤツを。C++0Xをテキトーに混ぜて。
#include <iostream>
#include <sstream>
#include <string>
#include <array>
#include <algorithm>
#include <numeric>
int main() {
const int N = 1000;
std::array<int,N+1> ary;
std::iota(ary.begin(),ary.end(),0);
std::ostringstream strm;
std::for_each(ary.begin(),ary.end(),[&](int n) { strm << n; });
std::string str = strm.str();
std::cout << std::count(str.begin(), str.end(), '0') << std::endl;
}