Page 2 #include<stdio.h> #include<iostream> using namespace std; char s[10001],str[80]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int j = 0; memset(s,'\0',sizeof(s)); while(gets(s)) { int len = strlen(s); int i = 0; while(i<len) { if(s[i]=='>') { j++; if(j>79)j=0; } else if(s[i]=='<') { j--; if(j<=0)j=0; } else if(s[i]!='\n' && s[i]!='\0') { str[j] = s[i]; j++; } i++; } memset(s,'\0',sizeof(s)); } for(int i = 0;i<80;i++) printf("%c",str[i]); return 0; } "at the beginning the e-screen contains 80 spaces" I add in begin memset(str,' ',sizeof(80)); I get WA#1 to former =( Thank you!!!You help me!!!I got AC!!!=) var s:array[1..100010] of char; i,j,k,l,now,lo:longint; a,t1,t2:string; begin a:=''; for i:=1 to 80 do a:=a+' '; i:=0; while not(eof) do begin inc(i);read(s[i]); end; lo:=i; now:=1; for i:=1 to lo do begin if (s[i]='<') then begin dec(now); if (now=0) then now:=1; continue; end; if (s[i]='>') then begin inc(now); if (now=81) then now:=1; continue; end; if now=1 then t1:='' else t1:=copy(a,1,now-1); if now=80 then t2:='' else t2:=copy(a,now+1,80-now-1); a:=''; a:=t1+s[i]+t2; t1:=''; t2:=''; inc(now); if (now=81)then now:=1; end; for i:=1 to 80 do write(a[i]); end. wrong on the following code /////////////////////// if(pos >maxline -1) pos = 0; a[pos++] = char; //////////////////// when test case: aaaaaaaaaaa.......a(total 80 a)<b b should in pos 1 instead of erasing pos 80
Yeah, my program's output is exactly "baaaaaaaaaa....a". But I still got WA#9. if(pos >maxline -1) pos = 0; a[pos++] = char; if (pos>maxline-1) pos=0; // may be this help for you Edited by author 12.11.2012 19:43 Remember, that in input there are "end-of-line characters". And you must read string lines until your find "end-of-file characters". If Java while (in.hasNextLine()) { char input[] = in.nextLine().toCharArray(); /* analyse-code */ } This method (while(in.hasNext***()) often use, when you don't know the number of input data or you can find "end-of-line characters" in text line. Edited by author 30.04.2009 18:26 and..... "...Assume that at the beginning the e-screen contains 80 spaces..." (for TestCase#1) "...The width of the screen is 80 symbols. When the cursor reaches left or right edge of the screen it is automatically placed at the first position to the left...." (for TestCase#4) Don't miss that! Edited by author 28.09.2009 14:17 A very easy problem. Just read teh description carefully, there are some traps inside. Here are a few typical mistakes: a) you forgot to fill the array with ' ' b) you're doing gets( buff ), and the size of buff is less than 10000 c) you're doing printf( "%s", out ), and you forgot to do out[80] = '\0' d) if the position becomes 80, you go to 79 instead of 0 e) you don't print trailing spaces Good luck! faint! I didn't see the word 'mistakes' ...... d) seems to be wrong, "When the cursor reaches left or right edge of the screen it is automatically placed at the first position to the left." so if the position becomes 80, you should go to 0. 1) For those who get WA 1 mb helps : with while (!cin.eof()) char c = cin.get(); i had WA 1 with char t[10000]; cin.getline(t, 1000); i had WA 9 ! 2) the problem says that the length of input is no more than 10000 characters but this code ... char t[10000]; cin.getline(t, 10000) ... get WA9 this : char t[20000]; cin.getline(t, 20000); get AC Strange, isn't it? Yes,It's very strange! ----------- char t[10001]; cin.getline(t,10000,'\n'); ---------- I got WA9. ----------- char t[10001]; cin.getline(t,10001,'\n'); ---------- I got AC! 1. Maybe you didn't add a '\0' at the end of string when reading by chars. 2. For maxlen=10000, array must be at least as big as 10001! in example writen--- "Look for second hamburger at computer and chairs.790 " there mustn't writen "790". number of "<" is bigger than answer. and why "790" in the end of sentence!! pls, explain it to me!!! thx!!! and i think it is right!! program Project1094; {$APPTYPE CONSOLE} uses SysUtils; var a : string[80]; i, j : integer; ch : char; f, f1 : textfile; begin assign(f, '1094.in'); assign(f1, '1094.out'); reset(f); rewrite(f1); i := 0; fillchar(a, sizeOf(a), 0); while not eof do begin read(ch); if ch = '>' then begin if i < 80 then begin inc(i); a[i] := ' '; end else i := 0; end; if (ch = '<') and (i > 0) then dec(i); if (ch <> '<') and (ch <> '>') then begin inc(i); a[i] := ch; end; end; for j := 1 to i do write(a[j]); close(f); close(f1); end. Edited by author 20.02.2008 23:05 I don't understand task.Please write me explanation on serchch@mail.ru(on russian),if you can.Thank you very much!!! The first one got AC but the second one got WA. I have initialized every char in ans to be ' '. OH, I see... I should let ans[80] to be '\0'... sorry..~ Edited by author 23.07.2007 21:58 int a = getc(stdin); read by simbol Before reading of spaces you must read rules of webboard! Speak in English! char ch; while(cin.get(ch)) { } можно вводить строку с пробелами целиком для string s; getline(cin, s); можно вводить символ char ch; ch = getchar(); эта штука позволяет вводить не только пробелы, но и символы перевода строк и прочее. в основном, пользуюсь этими двумя способами. Why i get Time Limit on test#1 with time 0.001 ?? I didn't understand the question!!! exactly what must our output 123<-456<-7890 <<<<<<<<<<<<<<<<to order <<<<<<<<<<<<<<<<<computers and ... initialize 80 chars to space output 80 chars Old tests were fixed: end-of-line characters were added in the end of input. New tests were added. Validator program was updated. Timelimit was decreased to 0.25 sec. After rejudge 26 authors got AC, but 512 lost AC. Edited by author 07.01.2007 07:34 I changed one symbol im my program and got AC once more. Maybe is there a bug again? In the problem statement it is said: "The single line of the input contains..." The SINGLE LINE means no '\n' characters! but this program gets Crash(1): #include <stdio.h> int main() { char c; while (scanf("%c", &c) == 1) { if (c == '\n') throw(0); } return 0; } And this one gets TL(1) #include <stdio.h> int main() { char c; while (scanf("%c", &c) == 1) { if (c == '\n') while(1); } return 0; } Isn't it strange ??? Edited by author 08.01.2007 20:43 Edited by author 09.01.2007 13:53 Interesting :-) I always thought that '\n'-character is the splitter for lines . That means if the number of '\n'-characters is K, so the number of lines is K+1... I think, that you should write in problem statement - "there is endline character after input" or "input is ended by endline char" I don't insist to change problem statement or tests, I just want to tell my opinion. I am sure, if you open the file with one of your test in text editor you will see 2 lines (the second one is empty). It is not very "interesting" to get WA because of that :-) If you open a file in a hexedit then you'll see that 0A0D symbols are the end of line, followed by EOF. So there is exactly 1 line, but notepad lets you to move your cursor on another line just because there was end of line though there isn't second line endeed. 1.I Just gets(str)NOT while(!feof(stdin))scanf("%c",&choice); 2.I Clear all member in output array = ' '; 3.I print With for(i = 0;i < 80;i++)printf("%c",data[i]) NOT printf("%s",data); 4.I print output with 80 len of Symbols NOW I GET AC!!! Thanks a lot. Using "gets" solved my problem with WA#1. It's interesting, why has it occured? it's very simple. there is '\n' at the end of input line )) gets delete it for you but you forgot about this when you read input byte after byte. [code deleted] Edited by moderator 16.03.2006 00:06 {WA1} program Sol; {$APPTYPE CONSOLE} {$O-} uses SysUtils; var ch:char; screen:array[1..80]of char; i,j,cx,cy:integer; begin { assign(input,'input.txt'); reset(input); assign(output,'output.txt'); rewrite(output);} read(ch); cx:=1; cy:=1; fillchar(screen,sizeof(screen),'#'); while not(eof(input)) do begin case ch of '<': begin dec(cx); if cx<1 then cx:=1 end; '>': begin inc(cx); if cx>80 then cx:=1; end; #10,#13:readln; else screen[cx]:=ch; inc(cx); if cx>80 then cx:=1; end; read(ch); end; for j:=1 to 80 do if screen[j]='#' then write('*') else write(screen[j]); { close(input); close(output);} end. {WA1} program Sol; {$APPTYPE CONSOLE} {$O-} uses SysUtils; var ch:char; screen:array[1..80]of char; i,j,cx,cy:integer; begin assign(input,'input.txt'); reset(input); assign(output,'output.txt'); rewrite(output); read(ch); cx:=1; cy:=1; fillchar(screen,sizeof(screen),'#'); while not(eof(input)) do begin case ch of '<': begin dec(cx); if cx<1 then cx:=1 end; '>': begin inc(cx); if cx>80 then cx:=1; end; #10,#13:readln; else screen[cx]:=ch; inc(cx); if cx>80 then cx:=1; end; read(ch); end; for j:=1 to 80 do if screen[j]='#' then write('*') else write(screen[j]); close(input); close(output); end. |
|