fork(1) download
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <vector>
  9. #include <map>
  10. #include <set>
  11. #include <iterator>
  12. #include <queue>
  13.  
  14. #define MAX(a,b) (a>b)?a:b
  15. #define MIN(a,b) (a>b)?b:a
  16. using namespace std;
  17. typedef long long int llint;
  18. typedef long int lint;
  19. template <typename T_>
  20. void fastread(T_ *a)
  21. {
  22. char c=0; *a=0;
  23. while(c<33){c=getchar();}
  24. while(c>33){*a=(*a<<3)+(*a<<1)+c-'0'; c=getchar();}
  25. }
  26.  
  27. int fast_str(char *a)
  28. {
  29. int len=0; char c=0;
  30. while(c<33){c=getchar();}//eat spaces
  31. while(c!='\n'){*a=c; ++len; ++a; c=getchar();}
  32. *a='\0';
  33. return len;
  34. }
  35.  
  36. int fast_wrd(char *a)
  37. {
  38. char c=0; int len=0;
  39. while(c<33){c=getchar();}
  40. while(c>33){*a=c; ++len; ++a; c=getchar();}
  41. *a='\0';
  42. return len;
  43. }
  44.  
  45. void fast_wrt(char *a)
  46. {
  47. while(*a!='\0')
  48. {
  49. putchar(*a);
  50. ++a;
  51. }
  52. }
  53.  
  54.  
  55.  
  56. int getDir(llint x1,llint y1,llint x2,llint y2)
  57. {
  58. if(y2>y1)//------> '/' is up
  59. return 1;
  60. else //------> '\' is down
  61. return 2;
  62. }
  63.  
  64. bool customSortFunction(const pair<llint,pair<llint,llint> >& a,const pair<llint,pair<llint,llint> >& b)
  65. {
  66. return ((a.second.second>b.second.second));
  67. }
  68.  
  69. int main()
  70. {
  71. //freopen("out.txt","w",stdout);
  72. vector<pair<llint,llint> > myvec;
  73. llint points;
  74. fastread(&points);
  75. llint x=0,y=0,tx,ty,toggle=0;
  76. myvec.push_back(make_pair(x,y));
  77. for(llint i=0;i<points;++i)
  78. {
  79. //cout<<i<<endl;
  80. //generate all points according to input and store
  81. fastread(&tx);
  82. if(toggle)
  83. {
  84. x += tx;
  85. y = y+ (-1*tx);
  86. }
  87. else
  88. {
  89. x += tx;
  90. y += tx;
  91. }
  92. toggle = !toggle;
  93. myvec.push_back(make_pair(x,y));
  94. }
  95.  
  96. vector<pair<llint,pair<llint,llint> > > allpoints;
  97. vector<pair<llint,pair<llint,llint> > >::iterator itr;
  98. pair<llint,llint>ptemp;
  99. for(int i=0;i<myvec.size()-1;++i)
  100. {
  101. //storing all intermediate points in the ECG graph
  102. llint xnow,ynow,xlast,ylast;
  103. xnow=myvec.at(i).first;
  104. ynow=myvec.at(i).second;
  105. xlast=myvec.at(i+1).first;
  106. ylast=myvec.at(i+1).second;
  107. int direction=getDir(xnow,ynow,xlast,ylast);
  108. switch(direction)
  109. {
  110. case 1:
  111. while(xnow<xlast)
  112. {
  113. ptemp=make_pair(xnow,ynow);
  114. //store direction along the points
  115. allpoints.push_back(pair<llint,pair<llint,llint> >(direction,ptemp));
  116. ++xnow; ++ynow;
  117. }
  118. break;
  119.  
  120. case 2:
  121. while(xnow!=xlast)
  122. {
  123. ptemp = make_pair(xnow,ynow-1);
  124. //store direction along the points
  125. allpoints.push_back(pair<llint,pair<llint,llint> >(direction,ptemp));
  126. ++xnow;
  127. --ynow;
  128. }
  129. break;
  130. }
  131. }//all points inserted
  132.  
  133. //now sort custom
  134. sort(allpoints.begin(),allpoints.end(),customSortFunction);
  135.  
  136. /*
  137.   for(int i=0;i<allpoints.size();++i)
  138.   {
  139.   cout<<allpoints.at(i).first<<" "<<allpoints.at(i).second.first<<","<<allpoints.at(i).second.second<<endl;
  140.   }
  141.   */
  142.  
  143.  
  144. /**
  145.   backslash ascii
  146.   **/
  147. char c=92;
  148. /****/
  149.  
  150.  
  151. llint currentY,j;
  152. /**
  153.   * start plot
  154.   * top-down plotting
  155.   **/
  156. for(llint i=0;i<allpoints.size();++i)
  157. {
  158. currentY=allpoints.at(i).second.second;
  159. llint previous=0,x;
  160. //plot all points in the same horizontal line
  161. for(j=i;j<allpoints.size()&&allpoints.at(j).second.second==currentY;++j)
  162. {
  163. //print spaces
  164. for(x=previous;x<allpoints.at(j).second.first;++x)
  165. {
  166. cout<<" ";
  167. }
  168. //print according to direction
  169. if(allpoints.at(j).first==1)
  170. cout<<"/";
  171. else
  172. cout<<c; //special backslash or '\'
  173. previous = x+1; //cursor continuation
  174. }
  175. for(llint y=x;y<allpoints.at(allpoints.size()-1).second.first;++y)
  176. cout<<" ";
  177. cout<<endl;//avoiding the final endl as it counts spaces while checking
  178. i=j-1;//continuation chained
  179. }
  180.  
  181.  
  182. return 0;
  183. }
  184.  
Success #stdin #stdout 0s 3440KB
stdin
3
1 5 1
stdout
/\     
  \    
   \   
    \  
     \/