AtCoder #002 の A を解いてみた
参加はしていなかったんですが、終わったあとに問題を見かけたので解いてみました。
[ソース]
#include <cstddef> #include <boost/preprocessor/repetition/enum.hpp> // // static print // template<std::size_t Index, typename String> constexpr char at_c(String const& str){ return Index >= str.length() ? char('\0') : str[Index]; } template<char... cs> struct chars{}; #define STRING_MAX_LENGTH 16 #define DECL_AT_C(z, n, text) \ at_c<n>(text) #define TO_STRING_TYPE(str) \ chars<BOOST_PP_ENUM(STRING_MAX_LENGTH, DECL_AT_C, str)> #include <boost/mpl/print.hpp> template<typename String> void static_print(){ namespace m =boost::mpl; typedef typename m::print<String>::type output; } #ifndef INPUT #define INPUT 2100 #endif #include <sprout/string.hpp> #include <sprout/operation.hpp> constexpr bool is_bissextile_year(std::size_t year){ return 1000 > year || year > 3000 ? throw("hage") : year % 400 == 0 ? true : year % 100 == 0 ? false : year % 4 == 0 ? true : false; } int main(){ typedef sprout::string<8> string; constexpr std::size_t n = INPUT; constexpr auto result = is_bissextile_year(n) ? sprout::realign_to<string>(sprout::to_string("YES")) : sprout::realign_to<string>(sprout::to_string("NO")); static_print<TO_STRING_TYPE(result)>(); static_assert(!is_bissextile_year(1001), ""); static_assert( is_bissextile_year(2012), ""); static_assert(!is_bissextile_year(2100), ""); static_assert( is_bissextile_year(2000), ""); return 0; }
[出力]
example: $g++ -DINPUT 2100 main.cpp In file included from D:\AtCoder\002\cpp\A\main.cpp|26| 0: D:boost/boost_1_49_0/boost/mpl/print.hpp: In instantiation of 'struct boost::mpl::print<chars<'N', 'O', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000'> >': main.cpp|33 col 42| required from 'void static_print() [with String = chars<'N', 'O', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000'>]' main.cpp|63 col 39| required from here boost\boost_1_49_0\boost\mpl\print.hpp|55 col 10| warning: comparison between signed and unsigned integer expressions [-Wsign-compare] enum {
constexpr の標準入力は define ですがなにか?
B もやろうと思ったんですが、日にちの計算がめんどくさかったので途中で投げました(ぁ。
constexpr Data_Time マーダー。