fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #define _USE_MATH_DEFINES
  5. #include <math.h>
  6.  
  7. std::vector<std::size_t> Shuffle(std::size_t N){
  8. std::size_t S = 0;
  9. std::size_t E = N;
  10. std::vector<std::size_t> vec;
  11. bool F = true;
  12. while (S != E){
  13. if (F){
  14. vec.push_back(S++);
  15. }
  16. else{
  17. vec.push_back(E--);
  18. }
  19. F = (!F);
  20. }
  21.  
  22. vec.push_back(S);
  23.  
  24. return vec;
  25. }
  26. template<class T>
  27. struct Vector2
  28. {
  29. T x, y;
  30. };
  31.  
  32. template<class T>
  33. Vector2<T> TransForm(Vector2<T>& Length, double RotRadian, Vector2<T>& Scale, Vector2<T>& Move)
  34. {
  35. Vector2<T> Ret = { 0, };
  36. double Sin = sin(RotRadian);
  37. double Cos = cos(RotRadian);
  38.  
  39. Ret.x = ((Length.x * Scale.x) * Cos) - ((Length.y * Scale.y) * Sin) + Move.x;
  40. Ret.y = ((Length.x * Scale.x) * Sin) + ((Length.y * Scale.y) * Cos) + Move.y;
  41.  
  42. return Ret;
  43. }
  44.  
  45. bool MakeHoge(std::string Str){
  46. std::vector<std::size_t> Vec = Shuffle(Str.size()-1);
  47. double R = Str.size() / 2;
  48. double Radian = M_PI / 180.0;
  49. double Angle = 360.0 / Str.size();
  50. Vector2<double> V{ 0, 0 };
  51. Vector2<double> S{ 1, 1 };
  52. Vector2<double> M{ R, R };
  53. Vector2<double> L{ R, 0 };
  54.  
  55. for (std::size_t i = 0; i < Vec.size(); i++){
  56. auto O = V;
  57. V = TransForm(L, Radian*((Angle*Vec[i])-90), S,M);
  58. if (i % 2 == 0) V.x = V.x - O.x;
  59. for (int j = 0; j < (int)(V.x); j++)std::cout << ' ';
  60. std::cout << Str[Vec[i]];
  61. if (i % 2 == 0)std::cout << std::endl;
  62. }
  63. return true;
  64. }
  65.  
  66.  
  67. int main(){
  68. std::string Str = "0123456789abc";
  69.  
  70. MakeHoge(Str);
  71. MakeHoge("lattattarararibirabirin");
  72.  
  73. return 0;
  74.  
  75. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
      0
   c     1
 b         2
a           3
9           4
  8       5
    7  6
           l
        n     a
     i           t
  r                t
 i                   a
b                     t
a                     t
r                    a
  i                 r
    b             a
      i        r
         r  a