I don't use ";" in the end. I use Console.Write() and not Console.WriteLine(). According to the interpreter my PIBAS programm is correct. Still I've got WA#1. I'd like to have some hints from people with C# AC. Disregard that. I don't understand how I checked my program a dozen times and didn't see the obviously wrong length of last substring! Funny thing about the interpreter provided by DR. Zhihua Lai: it does not react to substring length which is higher than the length of an actual string. That's why my PIBAS programm worked well in interpreter but gave me WA1 here. java public class MainClass { public static void main(String[] args) { System.out.println("A=\"'\";B='A=\"\";B=;?$(B,0,4)+A+$(B,4,4)+A+B+A+$(B,8,37)';?$(B,0,4)+A+$(B,4,4)+A+B+A+$(B,8,37)"); } } Edited by author 20.09.2022 09:22 Edited by author 20.09.2022 09:22 what is the problem's requirement? Do you agree this is a very interesting problem? I like writing such problems very much! I've done it! 1230 is among the most interesting problems i've ever solved! Imho, it's one of the best on timus. Cool! Mine is only 143 chars long =) Please, could you shortly tell me an algo of a introspective program? In any language:-) Here is my variant of an introspective program. It is written on Pascal. I think it will not be hard to convert it to C/C++ But I do not think it is easy make same under PIBAS, because PIBAS does not have for/while cycles :(. Some explanations: 1. Every const string (Stgs[ 2] := '...') Has " symbol not ' because Pascal needs doubled '' to mark single ' inside strings. 2. Chr(34) = ' 3. Chr(39) = " ----- Cut here ----- program IntrospectiveProgram; var Stgs: array[1..20] of String; i, j: Integer; begin Stgs[ 1] := ''; Stgs[ 2] := ' WriteLn("program IntrospectiveProgram;");'; Stgs[ 3] := ' WriteLn("var");'; Stgs[ 4] := ' WriteLn(" Stgs: array[1..20] of String;");'; Stgs[ 5] := ' WriteLn(" i, j: Integer;");'; Stgs[ 6] := ' WriteLn;'; Stgs[ 7] := ' WriteLn("begin");'; Stgs[ 8] := ''; Stgs[ 9] := ' for i := 1 to 20 do'; Stgs[10] := ' WriteLn(" Stgs[",i:2,"] := """, Stgs [i], """;");'; Stgs[11] := ' WriteLn;'; Stgs[12] := ''; Stgs[13] := ' for i := 1 to 20 do'; Stgs[14] := ' for j := 1 to Length(Stgs[i]) do'; Stgs[15] := ' if Stgs[i][j] = Chr(34) then'; Stgs[16] := ' Stgs[i][j] := Chr(39);'; Stgs[17] := ''; Stgs[18] := ' for i := 1 to 20 do'; Stgs[19] := ' WriteLn(Stgs[i]);'; Stgs[20] := 'end.'; WriteLn('program IntrospectiveProgram;'); WriteLn('var'); WriteLn(' Stgs: array[1..20] of String;'); WriteLn(' i, j: Integer;'); WriteLn; WriteLn('begin'); for i := 1 to 20 do WriteLn(' Stgs[',i:2,'] := ''', Stgs[i], ''';'); WriteLn; for i := 1 to 20 do for j := 1 to Length(Stgs[i]) do if Stgs[i][j] = Chr(34) then Stgs[i][j] := Chr(39); for i := 1 to 20 do WriteLn(Stgs[i]); end. ---- And here ---- > Here is my variant of an introspective program. It is written on > Pascal. I think it will not be hard to convert it to C/C++ > But I do not think it is easy make same under PIBAS, because > PIBAS does not have for/while cycles :(. > > Some explanations: > 1. Every const string (Stgs[ 2] := '...') Has " symbol not ' > because Pascal needs doubled '' to mark single ' inside strings. > 2. Chr(34) = ' > 3. Chr(39) = " > > ----- Cut here ----- > program IntrospectiveProgram; > var > Stgs: array[1..20] of String; > i, j: Integer; > > begin > Stgs[ 1] := ''; > Stgs[ 2] := ' WriteLn("program IntrospectiveProgram;");'; > Stgs[ 3] := ' WriteLn("var");'; > Stgs[ 4] := ' WriteLn(" Stgs: array[1..20] of String;");'; > Stgs[ 5] := ' WriteLn(" i, j: Integer;");'; > Stgs[ 6] := ' WriteLn;'; > Stgs[ 7] := ' WriteLn("begin");'; > Stgs[ 8] := ''; > Stgs[ 9] := ' for i := 1 to 20 do'; > Stgs[10] := ' WriteLn(" Stgs[",i:2,"] := """, Stgs > [i], """;");'; > Stgs[11] := ' WriteLn;'; > Stgs[12] := ''; > Stgs[13] := ' for i := 1 to 20 do'; > Stgs[14] := ' for j := 1 to Length(Stgs[i]) do'; > Stgs[15] := ' if Stgs[i][j] = Chr(34) then'; > Stgs[16] := ' Stgs[i][j] := Chr(39);'; > Stgs[17] := ''; > Stgs[18] := ' for i := 1 to 20 do'; > Stgs[19] := ' WriteLn(Stgs[i]);'; > Stgs[20] := 'end.'; > > > WriteLn('program IntrospectiveProgram;'); > WriteLn('var'); > WriteLn(' Stgs: array[1..20] of String;'); > WriteLn(' i, j: Integer;'); > WriteLn; > WriteLn('begin'); > > for i := 1 to 20 do > WriteLn(' Stgs[',i:2,'] := ''', Stgs[i], ''';'); > WriteLn; > > for i := 1 to 20 do > for j := 1 to Length(Stgs[i]) do > if Stgs[i][j] = Chr(34) then > Stgs[i][j] := Chr(39); > > for i := 1 to 20 do > WriteLn(Stgs[i]); > end. > ---- And here ---- char *f = "char *f = %c%s%c; void main(){printf(f, 34, f, 34, 10);%c" void main() { printf(f, 34, f, 34, 10); } The main point of my solution is, firstly, to become free of constant non-variable strings in output and, secondly, to use substring operator to replicate print. Let's define double quote as D, and single quote as S, sembol of endline as E: {{{ D='"';S="'";E=";" }}} After defining that, we need to print that string. Let's use support string C: {{{ C="C=D=S=E="; ... ?$(C,1,2)+D+C+D+E #printed definition of C +$(C,3,2)+S+D+S+E #printed definition of D ... #print the rest alike }}} But how we'll print this particular "?" operation? Let's append all that operator body to our support string C, and then print it's substring, which will represent needed operator: {{{ C="C=D=S=E=?$(C,1,2)+D+C+D+E+$(C,3,2)+S+D+S+E+$(C,5,2)+D+S+D+E+$(C,7,2)+D+E+D+E+$(C,9,78)"; }}} You can simply prove by yourself, that this substring is 78 symbols long. Thus, solution found. My full PIBAS code is 187 lines long. Edited by author 05.11.2011 03:44 Edited by author 05.11.2011 03:44 My PIBAS-program consists of 219 letters. Please, if you have shorter, share your program with me! My PIBAS Introspective program is 99 bytes long. My own solution is 89 chars long. The best known solution is 65 chars long. As for me, i've got OK for 187 chars in code Why i got Wa? Pascal [deleted] PIBAS [deleted] I write program for test my program and input and output not diffrence. \ SOS / Thank you I got AC. Hint for all Begin WriteLn('<PIBAS Code>'); End. This incorrect Begin Write('<PIBAS Code>'); End. This Correct. Edited by author 20.02.2006 21:11 Try the same without ';' in the end. There is strange thing, but program with ending ';' is incorrect. WriteLn is correct and can take AC this is my c++ program and i dont know why i get WA #include <iostream.h> main() {
cout<<"D='\"';J=\"'\";S=\"D=\"+J+D+J+\";J=\"+D+J+D+\";S=?$(S,1,14);?D;?'D=';?D;?'+';?'J';?'+';?'D';?'+';?'J';?'+';?D;?';J=';?D;?'+';?'D';?'+';?'J';?'+';?'D';?'+';?D;?$(S,12,146);?D;?";";?$(S,15,143);\";?$(S,1,14);?D;?'D=';?D;?'+';?'J';?'+';?'D';?'+';?'J';?'+';?D;?';J=';?D;?'+';?'D';?'+';?'J';?'+';?'D';?'+';?D;?$(S,12,146);?D;?";";?$(S,15,143);"; } better write PIBAS code only. try to write PIBAS interpreter, it will show your error at once. in your PIBAS code (thats begins after cout<<" and when \" replaced with ") at position 170 unexpected " there are doubled "; ...?D;?";";?$(S,15,143);... ^^^^^ here you shall replace one of quotes with some other simbol 1.You can't use ';' at the end of the program 2.You can't use space in the pro except in " " or ' '! Hope it will be helpful for you! Though I spent lot of time on it ,but it give me so much fun that I could never forget it!!! thanx a lot Edited by author 19.04.2010 08:32 It failed because the invalid definition of B. You can't use a " between a pair of ", but only between a pair of '. So you can change it to : B='"'. But this cause another bug, for you must output triple B in A. So, try to add a new variable C, C="'", and change the program a bit, and you will get AC. Good luck~ Why this program is not correct: PIBAS: A="""; B="B=;?'A='+A+A+A+';'+$(B,1,2)+A+B+A+$(B,3,41)"; ?'A='+A+A+A+';'+$(B,1,2)+A+B+A+$(B,3,41) Pascal: [code deleted] Edited by moderator 06.03.2006 18:54 "sequence cannot contain the quote character it is enclosed in" Thanks for idea! Create another myself I couldn't. But in this pattern except that told there is one additional small mistake. The task is really cool. I wrote a tiny interpreter, that does not support "$" (who needs it anyway, since the problem could be solved without it). If anyone wants it, mail me (vessko_at_softhome_dot_net) program ural1230; begin writeln('A="?''A="+''"''+"''+A+''"+''"''+";''+A";?''A="''+A+''";''+A'); end. The PIBAS prog is as follows: A="?'A="+'"'+"'+A+'"+'"'+";'+A"; ?'A="'+A+'";'+A • Use write instead of writeln. CR/LF characters are not allowed in PIBAS program. • And your program is not introspective, your output is A="?'A="'+A+'";'+A";?'A="'+A+'";'+A What do you think about it? Oh, I have already ACed my program without $. :) But my PIBAS program(203 bytes) is longer, than it could be . [some code in PIBAS, deleted by moderator] I think it is correct. But I got WA1. Edited by moderator 10.05.2004 14:57 You must submit a program on C/C++ or Pascal which writes to output introspective program on PIBAS No. I am not that foolish. I just print it out in mu program [some code in PIBAS, deleted by moderator] Edited by moderator 24.06.2004 17:02 There is a syntax error at position 40. Fix it and you get AC! ...+B+A+B+$... Can it be wrong? Sorry, error is at position 56: Instead of ?(A,1,3) must be ?$(A,1,3) |
|