445 - Marvelous Mazes

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

shorojini
New poster
Posts: 8
Joined: Sat Aug 16, 2008 8:14 am

445 WA.pls anyone help this helpless.pls

Post by shorojini »

:cry: i am getting wrong answer in this problem.
i am giving my code here.if there is not any prob in code then there must
be some prob in my input output system.please can anyone give me any solution and
some some sample input output.pls pls pls mark me my prob.pls pls pls. #include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
while(getline(cin,s))
{
int l=s.length();

int k=0;
for(int i=0;i<l;i++){

if(s>=48 && s<=57)
k=k+s-48;

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

else{
if(s=='b') {
for(int i=0;i<k;i++)
cout<<" "; }
else{
for(int j=0;j<k;j++)
cout<<s; }
k=0;
}

if(i==l-1)
cout<<"\n";

}




}
return 0;
}
shorojini
New poster

Posts: 4
Joined: Sat Aug 16, 2008 8:14 am
Top

scor_k
New poster
Posts: 4
Joined: Fri Sep 12, 2008 7:29 pm

445:TLE !!! please help me.......

Post by scor_k »

Code: Select all

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>


int main()
{

long long n,i,j,x,len,sum,a,k,b;
char arr[1000],c;

while(1)
{



scanf("%s",arr);

len=strlen(arr);
sum=0;
x=0;
while(x!=len)
{
for(i=x;i<len;i++)
{
if(isdigit(arr[i]))
sum=sum*10+arr[i]-'0';

else
break;
}


for(j=i;j<len;j++)
{
if(isupper(arr[j]) || arr[j]=='*' || arr[j]=='b')
{
for(a=0;a<sum;a++)
{
if(arr[j]!='b')
printf("%c",arr[j]);

if(arr[j]=='b')
printf(" ");

}
}

else if(arr[j]=='!')
printf("\n");

else
break;

}

x=j;
sum=0;



}


printf("\n");



}
return 0; 
}

mehrab
New poster
Posts: 10
Joined: Sat Jul 03, 2010 3:04 pm

Re: 445 WA

Post by mehrab »

i'm getting WA for 445 .
can anyone help me.

Code: Select all

#include <stdio.h>

int main()
{
	char string[100000],number=0,i=0,j=0;

	while(gets(string))
	{
		if(string[0]=='\0')
		{
			continue;
		}
		number=0;
		for(i=0;string[i]!='\0';i++)
		{
			if(string[i]>='0' && string[i]<='9')
				number+=(string[i]-48);
			
			else if((string[i]>='A' && string[i]<='Z') || string[i]=='b' || string[i]=='*' || string[i]=='!' || (string[i]>='a'&& string[i]<='z'))
			{
				if(string[i]=='b')
					string[i]=' ';
							
				for(j=0;j<number;j++)
				{
					if(string[i]=='!')
						printf("\n");
					else
						printf("%c",string[i]);
				}
				number=0;
			}
			
		}
		printf("\n");
		

	}
	return 0;
}

faiem
New poster
Posts: 14
Joined: Fri Aug 13, 2010 12:22 pm

WA: 445 - Marvelous Mazes

Post by faiem »

#include<stdio.h>

int main()
{
char ch;long I,sum=0,n=0;
while((ch=getchar())!=EOF)
{


if(ch>=48&&ch<=57)
{sum=sum+ch-48;n=1;
}

else
{
if(ch=='b')
{for(I=1;I<=sum;I++)
printf(" ");
}
else if(ch=='!')
{ printf("\n");

}

else if(ch!='\n')
{
for(I=1;I<=sum;I++)
printf("%c",ch);
}
sum=0;
}
if(n==1&&ch=='\n')
{
printf("\n");
n=0;sum=0;
}
}

return 0;
}
//why WA...PLz help.

varagrawal
New poster
Posts: 3
Joined: Sun Apr 24, 2011 10:33 pm

Re: 445 - Marvelous Mazes

Post by varagrawal »

@linux: Should your output say "I PWN NOOBS"? Coz the sample output you have given is ignoring the blank space in the 3rd line of the 3rd test case.

mathgirl
New poster
Posts: 36
Joined: Tue Apr 24, 2012 6:20 pm

445 Marvelous mazes WA

Post by mathgirl »

I have tried with previous inputs, and the outputs match. But still getting WA. Can anyone who got AC pls help me out ?

Code: Select all

Code removed after AC
Last edited by mathgirl on Thu May 10, 2012 10:24 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 445 Marvelous mazes WA

Post by brianfry713 »

Descriptions for different mazes should be separated by a blank line in the output.
Check input and AC output for thousands of problems on uDebug!

mathgirl
New poster
Posts: 36
Joined: Tue Apr 24, 2012 6:20 pm

Re: 445 Marvelous mazes WA

Post by mathgirl »

Thanks I got AC. The newline was the issue.

Sabiha_Fancy
New poster
Posts: 24
Joined: Mon Jul 16, 2012 3:43 pm

445 Marvelous Mazes

Post by Sabiha_Fancy »

Each time i submit the solution of this problem i am getting runtime error. If anyone would help me to find my error i will be glad.
here is my code #include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
char row[135];
int sum,flag,len,i,j;
flag = 0;
while(gets(row))
{
len = strlen(row);
sum=0;
if(len>0)
{
for(i=0; i<len; ++i)
{
if(row == '!')
{
printf("\n");
flag++;
}
else if(row == '\0')
{
if(row[i-1] == '!')
{
printf("\n");
break;
}
else
{
break;
}
}
else if(row>='0' && row<='9')
sum = sum+(row-'0');
else if(row == 'b')
{
for(j=1; j<=sum; ++j)
printf(" ");
sum = 0;
}
else if(row>='A' && row<='Z')
{
for(j=1; j<=sum; ++j)
printf("%c",row);
sum = 0;
}
else if(row == '*')
{
for(j=1; j<=sum; ++j)
printf("*");
sum = 0;
}
}
printf("\n");
}
}
return 0;
}
Fancy

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 445 Marvelous Mazes

Post by brianfry713 »

Increase the size of your row array and you'll get WA instead of RE. Put your code inside the code blocks.
Check input and AC output for thousands of problems on uDebug!

stadoblech
New poster
Posts: 3
Joined: Thu Nov 08, 2012 6:36 pm

445 - Marvelous Mazes - Wrong answer

Post by stadoblech »

im having wrong answer here

Code: Select all

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main { 
    
    public static void main(String[] args) {
        
        String line;
        Scanner scan = new Scanner(System.in);
        
        while(scan.hasNextLine()) {
            line = scan.nextLine();
            createMaze(line);
        }
    }
    
    public static void createMaze(String code) { 
        
        int tempNumberOfBlocks = 0;
        int numberOfBlocks = 0;
        String result = "";
        
        for(int i = 0; i < code.length();i++) { 
            if(Character.isDigit(code.charAt(i))) {
                numberOfBlocks = tempNumberOfBlocks + (int)(code.charAt(i)-48);
                tempNumberOfBlocks = (int)(code.charAt(i)-48);                
                //System.out.println(numberOfBlocks);
            } else if (Character.isLetter(code.charAt(i))) {
                tempNumberOfBlocks = 0;

                if((code.charAt(i))=='b') { 
                    for(int k = 0;k < numberOfBlocks;k++) { 
                        result += " ";
                    }
                    
                } else {
                    for(int k = 0;k < numberOfBlocks;k++) { 
                        result += code.charAt(i);
                    }
                }
                
            } else if (code.charAt(i)== '!') { 
                result += "\n";
                tempNumberOfBlocks = 0;
            } else if (code.charAt(i) == '*') { 
                result += "*";
                tempNumberOfBlocks = 0;
            } 
        }
        System.out.println(result);
    }
}
works great on my pc
anyone could help ?

p.s. begginer in java

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 445 - Marvelous Mazes - Wrong answer

Post by brianfry713 »

Try input 123T, output should be TTTTTT
Check input and AC output for thousands of problems on uDebug!

stadoblech
New poster
Posts: 3
Joined: Thu Nov 08, 2012 6:36 pm

Re: 445 - Marvelous Mazes - Wrong answer

Post by stadoblech »

brianfry713 wrote:Try input 123T, output should be TTTTTT
i tried and works fine... really dont know whats wrong ...

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 445 - Marvelous Mazes - Wrong answer

Post by brianfry713 »

You're only printing 5 T's, there should be 6 T's.
https://ideone.com/X2DXd1
Check input and AC output for thousands of problems on uDebug!

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

Re: 445 - Marvelous Mazes - Wrong answer

Post by f.maru »

i need some help what is wrong with this code?

Code: Select all

#include<iostream>
#include<string>
using namespace std;
void draw(int n,char t)
{
     if (t!='!')
     for(int i=1;i<=n;i++)
     cout<<t;
     else
     cout<<endl;
}
void drw (string a)
{
if (a!="")
{
  int  w=0;      
    while(w<=a.length())
    {
            
            if (a[w]=='!')
               draw(1,'!');                      
            if (int(a[w])>48 && int(a[w])<58)
            {
               int q=0; 
                      
               while(a[w]>48 && int(a[w])<58)
               {
                 q+=int(a[w])-48;
          
                 w++;           
               }    
                        
               if (a[w]=='b')                 
                      draw(q,' ');
                   else
                       draw(q,a[w]);
            }
              w++; 
    }
                         cout<<endl;
                        
}                           
}
int main()
{
    
    string b,c;
    b.clear();
    c.clear();
    while(getline(cin,c))
    {
                        // if(b!="")
                        // c=c+'!'+b;
                        // else
                       // {
                      
                         drw(c);
                         c.clear();
                    //    }
    }
}

Post Reply

Return to “Volume 4 (400-499)”