Page 1 of 7

### 445 WA

Posted: Sun Jul 07, 2002 6:26 pm
Why I get WA?

[pascal]Program p445;

Var Ch : Char;
T,i : Integer;

begin
T:=0;
While Not Eof(InPut) Do begin
While Eoln(InPut) do begin
Writeln;
T:=0;
end;
if Ch='!' then begin
Writeln;
T:=0;
end else
if Ch in ['0'..'9'] then T:=T+Ord(Ch)-Ord('0') else begin
for i:=1 to T do Write(Ch);
T:=0;
end;
While Eoln(InPut) do begin
Writeln;
T:=0;
end;
end;
end.[/pascal]

### 445help

Posted: Mon Aug 19, 2002 1:57 pm
program P445;
{\$APPTYPE CONSOLE}
uses
SysUtils;

var
str:array[1..1000000] of char;
len:integer;
procedure slv;
var
time,t,j:integer;
begin
t:=1;
while t<=len do begin
if str[t]='!' then begin
writeln;
t:=t+1;
end;
time:=0;
while (str[t]>='0')and(str[t]<='9') do begin
time:=time+ord(str[t])-48;
t:=t+1;
end;
if str[t]='b' then
for j:=1 to time do
write(' ')
else for j:= 1 to time do
write(str[t]);
t:=t+1;
end;
writeln;
end;

begin
while not eof do begin
len:=0;
while not eoln do begin
len:=len+1;
end;
while len<>0 do begin
slv;
len:=0;
while not eoln do begin
len:=len+1;
end;
end;
writeln;
end;
end.

### help me??

Posted: Sat Aug 31, 2002 12:04 am
can anyone tell me what should be the appropriate input routine for this problem in C?

i find two difficulties: 1) description for a row of a maze can be terminated either by ! sign or newline
2) so a newline may not always the indication of the description of another maze, it could be the description of the next row of the current maze

so what way the input routine formed and the out shoul be processsed?
at first when i solved it i get P.E....but when i was going to correct the error, i got straight WA..so help me

### 445 WA

Posted: Fri Jan 17, 2003 12:11 am
I need some input for this problem. It works for the sample input at ACM.

Thanks, Aur

Posted: Fri Jan 17, 2003 9:11 am
Mazes are separated one from other by EMPTY LINE. So if iput contains line, which contians only new line character, it's end of description of current maze

Best luck
Dominik

Posted: Wed May 07, 2003 1:02 pm
The following is my code, could anyone figure out why I always got WA?

[cpp]
#include <iostream>
#include <cctype>
using namespace std;

void main()
{
short repeat, i;

while(cin.good())
{
repeat=0;
while(*ptr!='\0')
{
if(isdigit(*ptr))
repeat+=short(*ptr-'0');
else if(*ptr=='b')
{
for(i=0; i<repeat; i++)
cout << ' ';
repeat=0;
}
else if(*ptr=='!')
{
repeat=0;
cout << endl;
}
else
{
for(i=0; i<repeat; i++)
cout << *ptr;
repeat=0;
}
ptr++;
}
cout << endl;
}
}
[/cpp]

### Problem 445

Posted: Fri Oct 17, 2003 9:32 pm
Hey, What's up fellas? Well, I've been attempting probelm 445. I think I've just about got the problem solved (I have the logic). When I submit the program, online judge gives me TLE.

I think my input is messing up the judge. I'm new to this and haven't done a problem when you have to use EOF. So, some tips would be helpful.

[cpp]
#include <iostream>
#include <cctype>

using namespace std;

//445

int main(){

char *input;
input = new char[133];

while(!cin.eof()){ //This part!!! I tried using cin.get() != EOF as well

cin.getline(input, 132);

int length = strlen(input);

int sum=0;
int numstatus=0;

for(int count = 0; count < length; count++){

if(isdigit(input[count]) && numstatus==0){
sum = (static_cast<int>(input[count])-48);
numstatus = 1;
}

else if(isdigit(input[count]) && numstatus==1){
sum += (static_cast<int>(input[count])-48);
}

else if(isalpha(input[count]) && isupper(input[count])){

for(int counter=0; counter < sum; counter++)
cout << input[count];

sum=0;
numstatus=0;
}

else if(input[count] == '*'){

for(int twocounter=0; twocounter < sum; twocounter++)
cout << input[count];

sum=0;
numstatus=0;

}

else if(input[count] == '!'){

cout << endl;

sum=0;
numstatus=0;
}

else if(input[count] == 'b'){

for(int threecounter=0; threecounter < sum; threecounter++)
cout << " ";

sum=0;
numstatus=0;

}

}

cout << endl;

delete [] input;
input = new char[133];

}

return 0;

}
[/cpp]

GCS

Posted: Sat Oct 18, 2003 6:02 pm
Try checking for EOF after reading a line. i.e. replace
[cpp]
while(!cin.eof()){
cin.getline(input, 132);
// etc.
}
[/cpp]
with
[cpp]
while( true ) {
cin.getline( input, 132 );
if( cin.fail() || cin.eof() ) {
break;
}
// etc.
}
[/cpp]

Also, note that it greatly simplifies things if repeated statements like
[cpp] sum=0;
numstatus=0;
[/cpp]
are factored out of all the if statements. (Similarly, your loops can be factored out). You'll end up with a solution that is half the length or smaller.

Posted: Sun Oct 19, 2003 4:52 am
This is my WA code.
[code] int number=0;
char printchar;
string line;

getline(cin, line);
while(cin.good()){
int len = line.length();
for(int i=0; i<len; i++){
if(isdigit(line[i]))
number += int(line[i]-'0');
else{
printchar = line[i];
if(printchar == 'b')
printchar = ' ';
else if(printchar == '!'){
number=0;
cout << endl;
continue;
}
while(number){
cout << printchar;
number--;
}
}
}
cout << endl;
getline(cin, line);
}[/code]

Or is there anything wrong?

### Thanks

Posted: Tue Oct 21, 2003 2:05 am

Thanks for the tips. Got the problem solved out of a bit more work. Your tips were very helpful!

Thanks a million!!!,

GCS

### 445 WA

Posted: Fri Jan 16, 2004 7:39 pm
Hello All,

If someone could give me some tips, I would appreciate that; I'm getting WA, and I have no idea what could be wrong. I think I'm pretty darn close. It might just be a formatting error that I am unaware of:

[cpp]
#include <iostream>
#include <cctype>
#include <cstring>

using namespace std;

int main(){

char *array;
array = new char[134];

while( cin.getline(array, 133) ) {

int sum=0;

for(int i=0; i <strlen(array); i++){

if(isdigit(array)){
sum += (array-48);
}

else if(array == 'b'){
for(int k=0; k<sum; k++){
cout << " ";
}
sum=0;
}

else if(array == '!')
cout << "\n";

else{
for(int j=0; j <sum; j++){

cout << array;
}

sum=0;
}

}
cout << endl;

delete [] array;
array = new char[134];

}

return 0;
}

[/cpp]

Thanks,

GCS

### Tips?

Posted: Tue Jan 20, 2004 3:01 am
Anyone able to offer any tips?

GCS

Posted: Fri Jan 23, 2004 5:23 am
i have a feeling that the 132 size limit was on the width of the maze not the input.

### Thanks

Posted: Sat Jan 24, 2004 12:52 am
Hey Betty,

Thank you so much for your response! I made one of the silliest mistakes by not reading the problem correctly!

Thanks again

GCS

### 445-WA.....WHY??????

Posted: Mon Mar 01, 2004 4:44 pm
#include<stdio.h>
void maze_create(int n);

char str[5000],ch;

main()
{
int i,flag;
flag = 0;
while(1)
{
i=0;
while(1)
{
ch = getc(stdin);
if(feof(stdin))
{
flag = 1;
break;
}
if(ch=='\n' && str[i-1] == '\n')
{
str[i++] = ch;
break;
}
str[i++] = ch;
}
if(flag == 1)
break;
else
maze_create(i);
}
}

void maze_create(int n)
{
int i,sum,j;
sum=0;
for(i=0;i<n;++i)
{
if(str[i]>=48 && str[i]<=57)
sum = sum + (str[i]-48);
else if(str[i] == 'b')
{
for(j=1;j<=sum;++j)
printf(" ");
sum = 0;
}
else if(str[i] == '!' || str[i] == '\n')
{
printf("\n");
sum = 0;
}
else
{
for(j=1;j<=sum;++j)
printf("%c",str[i]);
sum = 0;
}

}

}[c][cpp][/cpp][/c][code][c][cpp][color=blue][/color][/cpp][/c][/code]