LoginSignup
3
2

More than 5 years have passed since last update.

C++11言語で5の倍数と5のつく数字だけヒロミゴーする。5が3以上出たらさらにゴーゴーゴーする。

Posted at

動機

@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便利。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2