fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <random>
  4. #include <sstream>
  5. #include <cctype>
  6. #include <vector>
  7.  
  8. namespace Utility
  9. {
  10.  
  11. bool only_contains_spaces(std::string s)
  12. {
  13. return all_of(s.begin(), s.end(), isspace);
  14. }
  15.  
  16. int random_number(int min, int max)
  17. {
  18. std::random_device rd;
  19. std::uniform_int_distribution<int> dist(min, max);
  20. return dist(rd);
  21. }
  22.  
  23. std::string random_string(int length = 10)
  24. {
  25. std::string s = "";
  26. for (int i = 0; i < length; ++i)
  27. s += (char)random_number(32, 126);
  28.  
  29. return s;
  30. }
  31.  
  32. };
  33.  
  34. int main()
  35. {
  36. std::string stsf;
  37. std::getline(std::cin, stsf);
  38.  
  39. std::cout << "string to search for: " << stsf << std::endl << std::endl;
  40.  
  41. int index = 0;
  42. std::vector<std::string> words;
  43. std::string cursorline = "";
  44. int column = 0;
  45.  
  46. for (int i = 1; i <= 100; i++)
  47. {
  48. std::string input = Utility::random_string(20);
  49.  
  50. std::cout << input << " ";
  51.  
  52. if (index < stsf.size())
  53. {
  54. auto f = std::find(input.begin(), input.end(), stsf[index]);
  55. if (f != input.end())
  56. {
  57. std::string tilda = std::string((int)(f - input.begin()), '~');
  58. cursorline += tilda + std::string("^") + std::string(20 - (int)(f - input.begin()), ' ') ;
  59.  
  60. input = std::string(20 - (int)(f - input.begin()), ' ') + input;
  61. column = std::string(20 - (int)(f - input.begin()), ' ').size() + (int)(f - input.begin());
  62.  
  63. words.push_back(input);
  64. index++;
  65. } else
  66. cursorline += std::string(20, ' ') + std::string(" ");
  67. }
  68.  
  69. if (i % 3 == 0)
  70. {
  71. std::cout << std::endl;
  72. if (!Utility::only_contains_spaces(cursorline))
  73. {
  74. std::cout << cursorline << std::endl;
  75. }
  76. cursorline = "";
  77. }
  78. }
  79.  
  80. std::cout << std::endl << std::endl;
  81.  
  82. std::cout << std::string(column, '-') << std::string("v") << std::endl;
  83.  
  84. for (const auto& s : words)
  85. std::cout << s << std::endl;
  86.  
  87. std::cout << std::string(column, '-') << std::string("^") << std::endl;
  88. return 0;
  89. }
Success #stdin #stdout 2.4s 3040KB
stdin
Charlie bit me.
stdout
string to search for: Charlie bit me.

%MLB3Xf"P4X~7xlO?t&\ : !?;&D-:JFXh\g=5d.0 $oh[ZuTzQ4n[k&zI+4oO 
S@{RL@w6.(AYu!j)p$]\ 1QQkpb>9rl;Rg21|@V@* r.S$~"S08+3ALYsK_umi 
Q8z@K!En@Do^s-E%h&f- Z}J!]k9`vm2bLIo=5h"j >d6znBdY#zt$6z1LHz|G 
RNTI.TWWPd#\I^*05kZ: ,O8oB1*d)uVf`Ds.#go> [V4rHiB.CDN7MS<K[i%R 
                                          ~~~~~~~~^            
cNMVOFo5b\79@*S6TVp' }02I+LRX=%g*Z7$576QP I=MLiCBLmz%*D^\UMEY3 
RmV W#:v<Z3o.CUNn;ZN '@p4tyT2a)B/mn+IQBoB -G`<g)I+^V7ykOI0evu+ 
W X~&$0fys,))dS6+'DR eLXGAv6tz$R`%Cm!qG}m x";z}0*(~L2$v9dmw+^- 
mV^0'T.h+[InozBNFg[h 9dDVUn,$D5bpaF^I`BRG "FNqCP%sj 4oMnz^^=VM 
~~~~~~~^             ~~~~~~~~~~~~^                             
B>aNav;J(PP>_u:Ll?J4 4vIke/i>-Cs~2WNV2C.X ;kS.X\Mnm"8i=mTyp|Lm 
QTSYI+ICYh%OXjNSEqR< no9;T2<x6fzg"Sc_/Gc\ PQ=H6g]Lm9<;9r%T/tgg 
                                          ~~~~~~~~~~~~~^       
'!vdxuU8Ms}3NSb8"(fs ,;yg(tIy#ofQYSwnoDD0 R?m6m&Pd;!*8c^P>9tw* 
^:u5MVmZ8 =1qKP3X6hy g>`Gha5QNG/2VcUpV:|w 0t+k:?{n7eDH~q"~iq.% 
47kTRp89!C|Oki |cKU[ rAZ?FwNu hPF%Ut(!}:u F[P= \}MH'F|z~*(fxE* 
igPve&fn{XZNI58[x0)  8lK*i/uPB1?:+0D7%yw{ %MEsGHmTkhCbF%:Z^9|T 
                     ~^                                        
b<vtLf)_u?gE|~"-%77; =$H*Pre.f,O1o#b D:DM *RIuRBT? yS$- Kwq3F  
N~48XvZMbY*Lj0q@)*<y ?x8`joY]@AmW{h{%n110 WwY@iV.%F.jOG5Ipq;7H 
                                          ~~~~^                
TI:+UUCDTw+DT `cIAq+ MfGG#yR[Sg?b&+8'H'Ed ~y2S=bSM8_w!8u"1m#?. 
]}^DUV-qs$N]m$g#= k@ 1s3& 7;pxm(b15{5Ac=v rv&w*f[}T. 'ql;. FKV 
P[iI>t/f?u*Lg/*bQ.Uz @;2\)JxP+a{`P`:umChf W(DQ/~{|CJC0d@]3T_`c 
o~QC/%L~Z+u{,tRQX:n_ .&MAe`S8~*%v$+QV:aX- +Ly2/mE 49`Z+"EmWm'b 
                     ~~~~^                ~~~~~~~^             
%>enKdi*tH !\rF6okms Js2g<I^4s-~h'',IX_Yp C:Wt&-?jPbb/*P`ETAm$ 
                                          ~~~~~~~~~^           
{3Q-AN< Cx%8-pj{W'YD mL$@M`8Ms&r:zlP^gGel C3@hNF_SY+gsNZ%~oe') 
[ILMaNi]ytvE~yEr[0(! S.~IQ=w[-k]@9h2nh5o> Cz2B2DS/^zUDK3.-3.k" 
~~~~~~^                                                        
|1Q<J7=22<5uik,kFu*b [6.6hj:a1Ept|H]<E(mR 6s0TNT,tY+ w=)/<9dtM 
                     ~~~~~~~~~~~^         ~~~~~~~~~~^          
-_H[8,2}Nd@!eA4lzQ<I H?~FE7Ps1ThOU(:+@D9y d5^Eu0ZGmbZ%,V<#Ut:2 
                                          ~~~~~~~~^            
(SclZJDU}c}5tkLIF!xH r?g%K$?3`-CWSO<5!(#q `{f^.:?AH*#-g3/0p2i? 
8rc-LPKrD?;q.Qn>~cq) ?*Awj3&&*&eP~lE9zuLj 7;B}ty<Cjfk/nL`T'Gfw 
                     ~~~~~~~~~~^                               
t$t>{>zPN$9`<4dsRhsY T5 q]L(?ZFhyg1t0!]`V `s3*g8_jr6g-P'\!@Y$2 
t5$&_A&Xt(f]}+/w4<=^ 1BNju5@-ukx5i?:R(xv@ (O-kC,8{}<9!DA\z(@8g 
K*Pu-U_A!lO-je1;lV@( >9c5fe>1-54Dg!9%C9'm zgenQw;\.K8y#0M4w ;F 
                                          ~~~~~~~~^            
oHIWoxsUcJk[Z|Q<;hH3 3CZG33x5>3w*nZslNP`1 XyATG9@ o:2B$PZ:<L8] 
#`Q(QJ=~2]'V4p# ^so' W.@H/[D*(y6aqK!\&SK9 gAoqyk6mcs^dt5^:EhzL 
E7%$M41I}+e/n%s{ v=0 KBQo3._9RqXCu"#yJx]L X`M'='i.Y}qG;(C<.u)u 
2\yiMy)i]fj}=WEi'zk@ 

--------------------v
            [V4rHiB.CDN7MS<K[i%R
             mV^0'T.h+[InozBNFg[h
        9dDVUn,$D5bpaF^I`BRG
       PQ=H6g]Lm9<;9r%T/tgg
                   8lK*i/uPB1?:+0D7%yw{
                WwY@iV.%F.jOG5Ipq;7H
                .&MAe`S8~*%v$+QV:aX-
             +Ly2/mE 49`Z+"EmWm'b
           C:Wt&-?jPbb/*P`ETAm$
              [ILMaNi]ytvE~yEr[0(!
         [6.6hj:a1Ept|H]<E(mR
          6s0TNT,tY+ w=)/<9dtM
            d5^Eu0ZGmbZ%,V<#Ut:2
          ?*Awj3&&*&eP~lE9zuLj
            zgenQw;\.K8y#0M4w ;F
--------------------^