fork download
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <sstream>
  5. #include <string>
  6.  
  7. template <class T, class U>
  8. T lexical_cast(U input) {
  9. T result;
  10. std::stringstream b;
  11. b << input;
  12. b >> result;
  13. return result;
  14. }
  15.  
  16. template <int num>
  17. void show(std::string const &s) {
  18. show<num-1>(s + "0");
  19. show<num-1>(s + "1");
  20. }
  21.  
  22. template<>
  23. void show<0>(std::string const &val) {
  24. char *c[] = { "OLD", "WALLOW", "HERE", " SWORE" };
  25. char **cp[] = { c+3, c+2, c+1, c };
  26. char ***cpp = cp;
  27. printf("%.2s", **++cpp);
  28. printf("%.3s ", **++cpp+2);
  29. printf("%.3s", cpp[1][3]+2);
  30. printf("%s", val.length() < 6 ? "" : val.substr(6).c_str());
  31. printf("%s", *cpp[1]+1);
  32. printf("%c\n", *(*cpp[-2])+1);
  33. }
  34.  
  35.  
  36. int main() {
  37. std::vector<std::string> nums;
  38. for (int i=0; i<5; i++)
  39. if (i % 3 == 0)
  40. nums.push_back("fizz");
  41. else if (i % 5 == 0)
  42. nums.push_back("buzz");
  43. else
  44. nums.push_back(lexical_cast<std::string>(i));
  45.  
  46. std::for_each(nums.begin(), nums.end(), show<1>);
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.02s 2816KB
stdin
Standard input is empty
stdout
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!