Page 3 of 3
245 WA
Posted: Fri Jul 08, 2005 5:56 am
by liang1425
I always get WA,but I don't know why.
(The testdata is correct)
Please help me~~Thanks a lot
Code: Select all
/*Q245: Uncompress*/
#include <stdio.h>
#include <stdlib.h>
typedef struct listnode *ptr;
typedef struct listnode{
char word[50];
ptr link;
};
ptr creat(char *word){
ptr node;
node=malloc(sizeof(struct listnode));
strcpy(node->word,word);
node->link=NULL;
return node;
}
ptr insert(ptr list,char *word){
ptr node;
node=creat(word);
node->link=list;
return node;
}
inorder(ptr list,int n){
int i;
ptr phead,temp;
phead=list;
for(i=1;i<n;i++){
temp=list;
list=list->link;
}
printf("%s",list->word);
if(n>1){
temp->link=list->link;
list=insert(phead,list->word);
}
return list;
}
int main()
{
int p=0,k=0,s=0,n=0;
char t,word[50];
ptr list;
list=creat(" ");
while(scanf("%c",&t)!=EOF && t!='0'){
if(isalpha(t)){word[p++]=t; printf("%c",t); s=1;}
else if(t>=48 && t<58){ k=1; n*=10; n+=t-48; }
else{
if(!k && s){word[p]='\0'; list=insert(list,word); p=0; s=0; printf("%c",t);}
else if(k){list=inorder(list,n);k=0; n=0; printf("%c",t);}
else printf("%c",t);
}
}
return 0;
}
245 WA
Posted: Sun Aug 21, 2005 7:46 am
by Jeff
I don't dnow why....please help me....
245 Help
Posted: Sat Jan 07, 2006 6:59 am
by IRA
Input Data:
Dear Sally,
Please, please do it--1 would 4
Mary very, 1 much. And 4 6
8 everything in 5's power to make
14 pay off for you.
-- Thank 2 18 18--
0
Who can tell me why the output is like as follow?
==================================
Dear Sally,
Please, please do it--it would please
Mary very, very much. And Mary would
do everything in Mary's power to make
it pay off for you.
-- Thank you very much--
==================================
Thanks....
Posted: Mon Jan 09, 2006 10:24 pm
by Jan
Read carefully...
Input:
Code: Select all
Dear Sally,
Please, please do it--1 would 4
Mary very, 1 much. And 4 6
8 everything in 5's power to make
14 pay off for you.
-- Thank 2 18 18--
0
Think that you have a linked list of the words. Any time you get a word it will be added. If you get a number
n then go backwords and find the nth word. Add the word in the linked list and delete the previous one.
Output:
Code: Select all
Dear Sally,
Please, please do it--it would please
Mary very, very much. And Mary would
do everything in Mary's power to make
it pay off for you.
-- Thank you very much--
Hope it works.
245 Compile Error
Posted: Sat Feb 18, 2006 1:54 pm
by lulo
I can compile it in window, but don't know why there is a compile error when i submit the code to judge.
Code: Select all
#include <iostream>
#include <ctype.h>
using namespace std;
struct node {
char word[51];
node *next;
int charno;
node *prev;
};
void output(node *tail) {
node *ptr;
while (tail) {
cout << tail->word;
ptr = tail;
tail = tail->prev;
delete ptr;
}
}
int main() {
int i;
node *wlist;
node *ptr;
node *pop;
node *tail;
char c;
wlist = NULL;
ptr = wlist;
c = getchar();
while (true) {
// for char
while (isalpha(c)) {
i = 0;
pop = new node;
pop->charno = 0;
while (isalpha(c)) {
pop->word[i++] = c;
c = getchar();
}
pop->word[i] = 0;
if (! wlist) {
pop->next = pop;
pop->prev = NULL;
tail = pop;
} else {
pop->next = wlist;
pop->prev = NULL;
wlist->prev = pop;
}
wlist = pop;
}
// for number
while (isdigit(c)) {
if (c == '0') {
// output
output(tail);
exit(0);
}
i = c - '0';
c = getchar();
while (isdigit(c)) {
i *= 10;
i += c - '0';
c = getchar();
}
ptr = wlist;
pop = new node;
pop->charno = i;
for (;i>0;i--) {
if ((ptr->charno != 0) && (ptr->charno<i))
while ((ptr->charno != 0) && (ptr->charno<i)) ptr = ptr->next;
else {
ptr = ptr->next;
while ((ptr->charno != 0) && (ptr->charno<i)) ptr = ptr->next;
}
}
strcpy(pop->word, ptr->word);
pop->next = wlist;
pop->prev = NULL;
wlist->prev = pop;
wlist = pop;
}
// for non number and char
while (! (isdigit(c) || isalpha(c))) {
i = 0;
pop = new node;
pop->charno = -1;
while (! (isdigit(c) || isalpha(c)) && i<50) {
pop->word[i++] = c;
c = getchar();
}
pop->word[i] = 0;
if (! wlist) {
pop->next = pop;
pop->prev = NULL;
tail = pop;
} else {
pop->next = wlist;
pop->prev = NULL;
wlist->prev = pop;
}
wlist = pop;
}
}
return 0;
}
Posted: Wed Mar 15, 2006 2:02 am
by sclo
your code was way too long to read. It can definitely be done in less than 40 lines of code.
Posted: Wed Apr 05, 2006 12:19 pm
by Experimenter
sclo wrote:your code was way too long to read. It can definitely be done in less than 40 lines of code.
I am sorry about that.
Posted: Sat Sep 23, 2006 7:29 pm
by kwedeer
so - this is not direct reply for problem in the first post of thread - but - my usual request for help!!!
So - here is my code - array pieces[...] contain the words to be exchanged by numbers in encryption/decription. No special collection (e.g. very nice Classes.TStringList) is used as Judge gives compile error in such a case.
My code give the same result for test case - but judge gives WA. I have some thought that it mau be related that judge may handle carriage return/line feed for newlines differently than my WinXP/Delphi6 on which I am developing and testing.
Thanks a lot for any hint or advice in advance!!! Especially - it could be so great if someone coudl provide some tests cases against which my program fails to five the correct answer!!!
Code: Select all
program Prg2450(input, output);
{$APPTYPE CONSOLE}
//uses Classes;
var ch: char;
piece: String;
number: String;
intNumber: SmallInt;
errorCode: Cardinal;
posPiece,posNumber: Cardinal;
inPiece,inNumber: boolean;
chCode: integer;
pieces: array[0..1000000] of String;
positions: array[0..1000000] of Integer;
currentPieceNo: Integer;
currentPosition: Integer;
i: Integer;
inNewLine: Boolean;
ch13: char;
//strList: TStringList;
begin
{
AssignFile(Input, 'in02__.txt');
Reset(Input);
AssignFile(Output, 'out02__.txt');
Rewrite(Output);
}
setLength(piece,50);
setLength(number,50);
currentPieceNo:=1;
inPiece:=false;
inNumber:=false;
posPiece:=1;
posNumber:=1;
while not Eof(input) do
begin
if Eoln(input) then begin
// begin
if inPiece then begin
for i:=currentPieceNo downto 2 do begin
positions[i]:=positions[i-1];
end;
write(copy(piece,1,posPiece-1));
pieces[currentPieceNo]:=copy(piece,1,posPiece-1);
positions[1]:=currentPieceNo;
currentPieceNo:=currentPieceNo+1;
inPiece:=false;
posPiece:=1;
end;
if inNumber then begin
val(copy(number,1,posNumber-1),intNumber,errorCode);
write(pieces[positions[intNumber]]);
currentPosition:=positions[intNumber];
for i:=intNumber downto 2 do begin
positions[i]:=positions[i-1];
end;
positions[1]:=currentPosition;
inNumber:=false;
posNumber:=1;
end;
// end
ReadLn(input);
Read(input,ch);
chCode:=LongInt(ch);
//output together with tests - end or not to end
if chCode=48 then exit;
if chCode=13 then begin
ch13:=ch;
read(ch);
chCode:=LongInt(ch);
if chCode=48
then exit
else begin
writeln(output);
write(ch13);
end;
end else begin
writeln(output);
end;
end else begin
Read(input, ch);
chCode:=LongInt(ch);
end;
case chCode of
0..31,32,33..47, 58..64, 91..96, 125..255:
begin
if inPiece then begin
for i:=currentPieceNo downto 2 do begin
positions[i]:=positions[i-1];
end; //???
write(copy(piece,1,posPiece-1));
pieces[currentPieceNo]:=copy(piece,1,posPiece-1);
positions[1]:=currentPieceNo;
currentPieceNo:=currentPieceNo+1;
inPiece:=false;
posPiece:=1;
end;
if inNumber then begin
val(copy(number,1,posNumber-1),intNumber,errorCode);
// let 0-lth element is left unused
write(pieces[positions[intNumber]]);
currentPosition:=positions[intNumber];
// moving the current word to the front of list
for i:=intNumber downto 2 do begin
positions[i]:=positions[i-1];
end;
positions[1]:=currentPosition;
inNumber:=false;
posNumber:=1;
end;
if (chCode<>10)
then write(ch)
else writeLn(output);
end;
48..57:
begin
if ((not inNumber) and (chCode=48)) then exit;
number[posNumber]:=ch;
posNumber:=posNumber+1;
inNumber:=true
end;
else
begin
piece[posPiece]:=ch;
posPiece:=posPiece+1;
inPiece:=true
end;
end; // case
end; // while
end.
Re: 245 WA
Posted: Wed Jul 10, 2013 4:57 pm
by t.tahasin
Re: 245 WA
Posted: Wed Jul 10, 2013 10:25 pm
by brianfry713
Input:
Code: Select all
Dear Sally,
Please, please do it--1 would 4
Mary very, 1 much. And 4 6
8 everything in 5's power to make
14 pay off for you.
-- Thank 2 18 10--
0
Output should be:
Code: Select all
Dear Sally,
Please, please do it--it would please
Mary very, very much. And Mary would
do everything in Mary's power to make
it pay off for you.
-- Thank you very power--
Re: 245 WA
Posted: Fri Jul 12, 2013 7:33 am
by t.tahasin
@brianfry713: Thank you very much. Now I got accepted. I didn't notice that type of errors first time.