Brasil, USA, or Argentina
{| |- | O L in T |}
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #define size 400 using namespace std; char infix[size]="\0",postfix[size]="\0",Stack[size]; int top; int precedence(char ch) { switch(ch) { case '^':return 5; case '/':return 4; case '*':return 4; case '+':return 3; case '-':return 3; default:return 0; } } char Pop() { char ret; if(top!=-1) { ret=Stack[top]; top--; return ret; } else return '#'; } char Topelem() { char ch; if(top!=-1) ch=Stack[top]; else ch='#'; return ch; } void Push(char ch) { if(top!=size-1) { top++; Stack[top]=ch; } } int braces(char* s) { int l,r; l=0;r=0; for(int i=0;s[i];i++) { if(s[i]=='(') l++; if(s[i]==')') r++; } if(l==r) return 0; else if(l<r) return 1; else return -1; } int main() { char ele,elem,st[2]; int T,prep,pre,popped,j=0,chk=0; cin>>T; while(T--) { j=0;chk=0;top=-1; strcpy(postfix," "); cin>>infix; chk=braces(infix); if(chk==0) { for(int i=0;infix[i];i++) { if(infix[i]=='(') { elem=infix[i]; Push(elem); } else if(infix[i]==')') { while((popped=Pop())!='(') { postfix[j++]=popped; } } else if(infix[i]=='^'infix[i]=='/'infix[i]=='*'infix[i]=='+'infix[i]=='-') { elem=infix[i]; pre=precedence(elem); ele=Topelem(); prep=precedence(ele); if(pre>prep) Push(elem); else { while(prep>=pre) { if(ele=='#') break; popped=Pop(); ele=Topelem(); postfix[j++]=popped; prep=precedence(ele); } Push(elem); } } else { postfix[j++]=infix[i]; } } while((popped=Pop())!='#') postfix[j++]=popped; postfix[j]='\0'; cout<<postfix; } } }
O t t o
n n n n n n n n n n n n n n n o o o o o o o o o o o o o t t t t t t t t t t t h h h h h h h h h h h h h h i i i i i i i i i i n n n n n n n n n n g g g g g g gg g g g g g g g gg gg g
t-o-m-a-t-o
G O T O T H E D O C T O R O R T A L K T O S O M E O N E !
-18 1i 18 1i,16 1h 2cl rs,-16 1h -1lf -58,-11 -3b -15 -40 -17 -4p -15 -5f -m -60 -5 -5n -9 -54 -l -4m,-i -4l -13 -4i,-8 -3i -8 -45 -2 -4l b -4b,h -3k 12 -3q i -44 5 -3n 9 -34 o -2p 1c -2p,1v -43 1i -3p 1r -39 2c -37 27 -2n 1o -2k,31 -40 2h -3u 2o -3e 37 -34 34 -2k,34 -2k 2j -2g,-8 -2a f -26 16 -22 1n -21 14 -1k g -1a -2 -11 k -s 1b -r,-60 -30 -58 -2u -4j -2r -3v -2q,-5u -2u -5i -2f -52 -28 -4t -2s -4s -3i -5g -3f -5u -32,4k -1t 5e -1p 65 -1m 6c -12 65 -h 6s -l 7f -11 75 -1m 6k -22 65 -1m,2cj rn 2cl qr 2co PS 2cq ou 2cr o4 2cs nc 2ct mn,2cl om 2c4 p3 2bc p8 2ak pd 2b8 po 2bu PS 2ch pv 2bp q2 2b0 q3 2ac q3 2b1 qe 2bp qp 2ci r3##O 25v gk,O 25s gk,O 25s gs,O 2a6 j4,O 2an j7,O 2al j7,O 29s j4,O 29h j4,O 298 j2,O 290 j2,O 28t it,O 28t io,O 290 ih,O 290 ic,O 292 i4,O 292 hs,O 293 hj,O 293 h6,O 293 gu,O 292 gn,O 292 gd,O 292 gd,O 289 j2,O 284 j2,O 27t j2,O 27r j2,O 27l j2,O 27c j2,O 277 j2,O 276 j2,O 26q ij,O 271 io,O 271 ie,O 271 i2,O 271 i2,O 271 i1,O 276 HQ,O 274 hd,O 272 gl,O 272 gq,O 272 h6,O 272 hd,O 271 hl,O 271 j5,O 274 hj,O 274 hb,O 276 gl,O 276 gi,O 268 hs,O 261 hs,O 25l HQ,O 25g hn,O 250 hi,O 24p hi,O 261 io,O 25q io,O 25i io,O 253 im,O 24n io,O 24n io,O 24n ij,O 24p ie,O 24r i9,O 24r i2,O 24p hn,O 24p h8,O 24r gu,O 24s gu,O 250 gu,O 256 gu,O 258 gu,O 25b gu,O 25k gq,O 25l gq,O 243 hb,O 242 he,O 23t i7,O 23r io,O 23o it,O 23o j4,O 23u ij,O 240 ib,O 240 i4,O 242 ht,O 242 HQ,O 242 h8,O 242 gu,O 242 gu,O 23r hv,O 23p hv,O 23j i1,O 23h i1,O 23c i2,O 235 i4,O 232 i2,O 22o ho,O 22h ic,O 22h ij,O 22g iv,O 22j i9,O 22l i6,O 22m hs,O 22m hj,O 22m h9,O 22m h4,O 22m gu,O 22m gu,O 2a1 pH,O 2a1 pH,O 29u pn,O 29n pn,O 29n pm,O 29k p7,O 29d p3,O 298 pH,O 298 pr,O 29i q6,O 29u q6,O 2a6 pk,O 2a6 p8,O 2a5 p3,O 29u qd,O 2a1 q3,O 2a5 pk,O 2ab pf,O 2ab pi,O 2a3 pi,O 6e -1i,O 6c -1a,O 6b -17,O 6c -m,O 6g -k,O 6m -k,O 72 -j,O 75 -13,O 77 -1d,O 7c -1h,O 75 -10,O 75 -10,O 6v -1a,O 6r -1i,O 6o -1k,O 6j -1m,O 6g -1m,O 69 -1m,T -5a -3b,T -5a -3b,T -5f -3b,T -5q -3b,T -5q -31,T -5q -2n,T -5n -2p,T -5a -31,T -51 -3e,T -53 -36,T -55 -34,T -5a -2u,T -58 -2k,T -58 -2i,T -56 -2l,T -1io -5t,T -1is -5t,T -1j2 -62,T -1k4 -5k,T -1j7 -5p,T -1it -5p,T -1id -5h,T -1ij -5c,T -1j1 -57,T -1jl -5p,T -1jv -5u,T -1j4 -5m,T -1i1 -5m,T -1j9 -5p,T -1jg -5p,T -1je -5u,T -14b -7q,T -147 -7q,T -147 -81,T -14b -81,T -14c -81,T -14g -81,T -14g -81,T -13s -b2,T -13s -au,T -13t -at,T -13v -AA,T -13v -9q,T -144 -99,T -147 -8v,T -147 -91,T -146 -92,T -142 -9t,T -146 -a2,T -146 -a7,T -13v -am,T -13t -bc,T -13t -bi,T -13t -bm,T -13t -c3,T -13v -c8,T -16r -ao,T -15e -c8,T -15e -c5,T -15f -br,T -15k -bd,T -15k -b5,T -15m -au,T -15m -ak,T -15o -ae,T -15p -a7,T -15r -9r,T -15t -9j,T -15t -97,T -15t -8n,T -15u -8j,T -15u -8s,T -162 -92,T -167 -96,T -168 -9b,T -168 -9e,T -16a -9m,T -16h -a2,T -16i -a9,T -16m -ah,T -16s -b3,T -171 -bi,T -176 -c3,T -176 -bu,T -178 -bn,T -17d -bc,T -17f -b3,T -17i -at,T -17i -aj,T -17i -ac,T -17i -a7,T -17i -a2,T -17k -9t,T -17n -9m,T -17p -9h,T -17p -99,T -17p -92,T -17p -8s,T -17p -8n,T -17n -8i,T -18n -bu,T -18n -bu,T -192 -br,T -194 -br,T -196 -br,T -19e -bs,T -19j -bu,T -18n -a9,T -194 -a9,T -19j -ac,T -19q -aj,T -1a0 -aj,T -1a9 -ak,T -1a9 -ac,T -1aa -9v,T -1a7 -9r,T -18v -91,T -197 -92,T -19e -94,T -19l -97,T -19q -99,T -1a7 -99,T -1a7 -99,T -1a7 -9b,T -1a7 -9h,T -1a5 -a7,T -1a5 -ac,T -1a4 -ao,T -1a0 -ba,T -1a2 -bm,T -19v -bm,T -19r -bm,T -19h -br,T -1au -bi,T -1au -bi,T -1b7 -ba,T -1b8 -b7,T -1bc -aj,T -1bd -af,T -1bf -AA,T -1bh -a7,T -1br -9o,T -1br -9o,T -1cb -9e,T -1cb -9e,T -1cb -9e,T -1cf -9h,T -1cg -9o,T -1cn -a5,T -1cv -ak,T -1d4 -b7,T -1d4 -b7,T -1cq -at,T -1cf -9o,T -1cg -9r,T -1cp -ae,T -1d8 -bh,T -1ee -9r,T -1eh -9r,T -1et -9t,T -1f4 -9v,T -1em -b5,T -1eg -b0,T -1eb -af,T -1e9 -a4,T -1e4 -9q,T -1dn -8t,T -1dn -8t,T -1dn -97,T -1ds -9l,T -1e1 -a2,T -1em -ar,T -1em -bd,T -1fk -9g,T -1fk -99,T -1fp -8s,T -1fr -8s,T -1fe -9l,T -1f9 -ac,T -1fk -9h,T -1fh -9r,T -1f9 -aj,T -1f9 -aj,T -1f7 -at,T -1ev -b2,T -1eq -bc,T -1gd -b7,T -1h6 -ba,T -1gn -ba,T -1hf -ba,T -1h8 -a4,T -1gm -9j,T -1gp -9j,T -1h0 -9j,T -1h5 -9l,T -1hd -9o,T -1hk -9q,T -1hg -8l,T -1h3 -8g,T -1gn -8e,T -1gs -8e,T -1gs -8e,T -1hi -8j,T -1hl -8l,T -1hl -8l,T -1hk -92,T -1hp -9g,T -1hp -9t,T -1hn -9m,T -1hl -9g,T -1hl -a5,T -1hl -a5,T -1hl -ac,T -1hp -ap,T -1hp -af,T -1hp -b3,T -1hp -b3,T -1hp -b3,T -1kj -94,T -1kh -94,T -1kc -8n,T -1io -am,T -1io -ak,T -1in -aj,T -1it -a7,T -1it -8q,T -1it -8q,T -1it -8v,T -1iv -9h,T -1iv -9r,T -1it -a7,T -1iq -b2,T -1j6 -9l,T -1j6 -9l,T -1jc -9l,T -1jj -9m,T -1jv -9t,T -1jq -9r,T -1ke -8i,T -1ke -96,T -1ke -99,T -1ke -9b,T -1ke -9h,T -1kc -9q,T -1kc -9r,T -1kc -a4,T -1ke -a7,T -1ke -ah,T -1ke -ao,T -1ke -ao,T -1ke -b0,T -1jq -5h,T -1jq -5h,T -1k4 -5j,T -1kf -5o,T -1ke -5o,T -1jl -5o,T -1jt -60,T -1k0 -63,T -1k5 -65,T -1kj -62,T -1kj -5u,T -1kj -5r
n n n n n n n n n n n n n n n o o o o o o o o o o o o o t t t t t t t t t t t h h h h h h h h h h h h h h i i i i i i i i i i n n n n n n n n n n g g g g g g gg g g g g g g g gg gg g
8 t on a o means 8 tentacles on a octopus.
T-T-O-T-O-U-C-H-Down
Constitution.