動機
@kmagai さんのGo言語で5の倍数と5のつく数字だけヒロミゴーすると、
@Joe-noh さんのElixir言語で5の倍数と5のつく数字だけヒロミゴーするが楽しそうだったので。
ルールは5がつく数字でExotic、5の倍数でJapan、両立したらExotic Japan。さらに、5が3回以上出てきたときはGoGoGo!!!。
コード
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
const auto isGoGoGo= [](int i) -> string {
const string str = to_string(i);
return count( str.begin(), str.end(), '5' ) >= 3 ? "GoGoGo!!! ":"";
};
const auto isExotic = [](int i) -> string {
const string str = to_string(i);
return find( str.begin(), str.end(), '5' ) != str.end() ? "Exotic ":"";
};
const auto isJapan = [](int i) -> string {
return i % 5 == 0 ? "Japan ":"";
};
void hiromi( int eye)
{
for(int i=0; i<=eye; i++)
{
cout << i << " " << isGoGoGo(i) << isExotic(i) << isJapan(i) << endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
hiromi(240000000);
return 0;
}
所感
STL
便利。C++11
便利。