706 - LCD Display

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

Moderator: Board moderators

A Faltoo Fellow
New poster
Posts: 3
Joined: Thu Jul 03, 2003 2:30 pm
Location: Bangladesh

706 What's are the critical I/O

Post by A Faltoo Fellow »

Some body plz help me.

I see my propram ok. But the judge is replying as WA :o .

I think I may have problem in choosing the horizontal & veritcal lines. Some one plz tell me its ASCII code.
:D ( I took them as '-' (minus) and '|' (OR) ).

If I don't have any mistake in symbols. then tell me some critical I/O

A Faltoo Fellow
New poster
Posts: 3
Joined: Thu Jul 03, 2003 2:30 pm
Location: Bangladesh

706

Post by A Faltoo Fellow »

:lol: :lol: :lol:
I Have Got it Accepted Now. :oops: :oops: :oops:

Thozz
New poster
Posts: 5
Joined: Tue Oct 28, 2003 10:46 pm
Location: Madrid

Post by Thozz »

Hi!. I've dealed with ASCII code, blanks, zero size, eight digits numbers... but I always get WA. Does anyone know about the critical input??.

Jer
New poster
Posts: 10
Joined: Wed Nov 19, 2003 2:07 pm

the output form??

Post by Jer »

this is my output form :

3 1234567
*******aaa***aaa*********aaa***aaa***aaa
****b*****b*****b*b***b*b*****b*********b
****b*****b*****b*b***b*b*****b*********b
****b*****b*****b*b***b*b*****b*********b
*******aaa***aaa***aaa***aaa***aaa
****b*b*********b*****b*****b*b***b*****b
****b*b*********b*****b*****b*b***b*****b
****b*b*********b*****b*****b*b***b*****b
*******aaa***aaa*********aaa***aaa

I change "-"->"a","|"->"b"," "->"*" (and this's not point)
I want to know the the final " "(space)whether i have to cut it,
and put the text to new line..........

and the 706 prblem is also let me eat "WA" much time.........

Thozz
New poster
Posts: 5
Joined: Tue Oct 28, 2003 10:46 pm
Location: Madrid

Post by Thozz »

You should complete with blanks your lines till the end. I mean... all the lines must have the same width, and your fifth line:

*******aaa***aaa***aaa***aaa***aaa

is not completed:

*******aaa***aaa***aaa***aaa***aaa******

I still got WA!!! :oops:

gullutc
New poster
Posts: 3
Joined: Wed Dec 10, 2003 12:02 pm

706 WA

Post by gullutc »

Why !!!? :(

[c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

static char map[10][5][4]={
{" - ",
"| |",
" ",
"| |",
" - "},

{" ",
" |",
" ",
" |",
" "},

{" - ",
" |",
" - ",
"| ",
" - "},

{" - ",
" |",
" - ",
" |",
" - "},

{" ",
"| |",
" - ",
" |",
" "},

{" - ",
"| ",
" - ",
" |",
" - "},

{" - ",
"| ",
" - ",
"| |",
" - "},

{"-- ",
" |",
" ",
" |",
" "},

{" - ",
"| |",
" - ",
"| |",
" - "},

{" - ",
"| |",
" - ",
" |",
" - "}
};

void do_display(int n, char *nb)
{
int i, j, k;
int l=strlen(nb);

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

putchar(map[( nb[i]-'0')][0][0]);
for(j=0; j<n; j++)
putchar(map[( nb[i]-'0')][0][1]);
putchar(map[( nb[i]-'0')][0][2]);
if(i!=l-1)
putchar(' ');
}
putchar('\n');

for(i=0; i<n; i++)
{
for(j=0; j<l; j++)
{
putchar(map[( nb[j]-'0')][1][0]);
for(k=0; k<n; k++)
putchar(map[( nb[j]-'0')][1][1]);
putchar(map[( nb[j]-'0')][1][2]);
if(j!=l-1)
putchar(' ');
}
putchar('\n');
}

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

putchar(map[( nb[i]-'0')][2][0]);
for(j=0; j<n; j++)
putchar(map[( nb[i]-'0')][2][1]);
putchar(map[( nb[i]-'0')][2][2]);
if(i!=l-1)
putchar(' ');
}
putchar('\n');

for(i=0; i<n; i++)
{
for(j=0; j<l; j++)
{
putchar(map[( nb[j]-'0')][3][0]);
for(k=0; k<n; k++)
putchar(map[( nb[j]-'0')][3][1]);
putchar(map[( nb[j]-'0')][3][2]);
if(j!=l-1)
putchar(' ');
}
putchar('\n');
}

for(i=0; i<l; i++)
{
putchar(map[( nb[i]-'0')][4][0]);
for(j=0; j<n; j++)
putchar(map[( nb[i]-'0')][4][1]);
putchar(map[( nb[i]-'0')][4][2]);
if(i!=l-1)
putchar(' ');
}
putchar('\n');
}

int main()
{
int s;
char nb[20];

while(2==fscanf(stdin, "%d %s", &s, nb))
{
if(!s)
break;
do_display(s, nb);

putchar('\n');
}

return EXIT_SUCCESS;
}
[/c]

kiha
New poster
Posts: 37
Joined: Sat Dec 20, 2003 10:59 pm

Post by kiha »

Er ... :/ maybe you could put some hints for this problem here , for example what to do if the size is 0 , or anything ... thanks in advance

Thozz
New poster
Posts: 5
Joined: Tue Oct 28, 2003 10:46 pm
Location: Madrid

Please!, please!!!.

Post by Thozz »

Hi!. I'm also looking for hints for this problem. I think my program gives a right answer. I've tried with 0 size... but still got WA :roll:

Thanks in advance!. :wink:

kiha
New poster
Posts: 37
Joined: Sat Dec 20, 2003 10:59 pm

Post by kiha »

Yupeeeeeeeeee

I got Accepted [P.E.] on this problem. I will try to get AC without P.E. , but I have some hints for you who get WA on this problem :
1) if you write in Pascal [I don't know how is it like in C/C++] and remember the number as a string , be careful if the last character of this string is a white space
2) remember to output one blank line after each test case

I know these are stupid hints already written in the Problem Statement, but in hurry you might have missed them.
If you follow my hints and still get WA, email me [kiha@op.pl] and I can send you my code in Pascal. If so, please create a Subject of the message like 'Problem 706' or anything so that I won't delete your message as a rubbish.

Good luck to you solvers :D
kiha

Thozz
New poster
Posts: 5
Joined: Tue Oct 28, 2003 10:46 pm
Location: Madrid

Post by Thozz »

Hi!. Thanks a lot for your hints!!. I will try and deal with the problem as soon as posible. Unfortunately, I'm now very busy :( .

Thanks again!! :D

wanderley2k
New poster
Posts: 28
Joined: Mon Mar 01, 2004 11:29 pm

I try, try try and nothing

Post by wanderley2k »

I try to submit and only answered is Accepted (P.E). I am test more line in end file and more blank spaces in end line and nothing.

I submit the code in programming-challenges.com and I recived: "Solved"

I don't know what can be?

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja »

Dear, A Faltoo Fellow
Compare with before and after accepted problem, what is your difference points ?
I received all correct answer with my own test data.
But I don't understand why I got WA again and again... T_T
Plz help me.

regina
New poster
Posts: 4
Joined: Mon May 10, 2004 11:57 pm

I keep getting WA too:

Post by regina »

What is wrong with this code? -- I tried every possible input:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

class LCD
{
private:
char* disp[23];
int size;
public:

LCD()
{
for (int i = 0; i<23; i++)
{
disp = NULL;
}
}

~LCD()
{
if (disp)
delete[] disp;
}

void AddNumber(int number)
{
int index = 0;
if (strcmp(disp[0], "") != 0) //this is the first row
{
BlankColumn();
}
switch (number)
{
//draw a zero
case 0:
index = DashMiddle(index);
index = LineBackAndFront(index);
index = BlankLine(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
break;

case 1:
index = BlankLine(index);
index = LineBack(index);
index = BlankLine(index);
index = LineBack(index);
index = BlankLine(index);
break;
case 2:
index = DashMiddle(index);
index = LineBack(index);
index = DashMiddle(index);
index = LineFront(index);
index = DashMiddle(index);
break;
case 3:
index = DashFront(index);
index = LineBack(index);
index = DashFront(index);
index = LineBack(index);
index = DashFront(index);
break;
case 4:
index = BlankLine(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
index = LineBack(index);
index = BlankLine(index);
break;
case 5:
index = DashMiddle(index);
index = LineFront(index);
index = DashMiddle(index);
index = LineBack(index);
index = DashMiddle(index);
break;
case 6:
index = DashMiddle(index);
index = LineFront(index);
index = DashMiddle(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
break;
case 7:
index = DashMiddle(index);
index = LineBack(index);
index = BlankLine(index);
index = LineBack(index);
index = BlankLine(index);
break;
case 8:
index = DashMiddle(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
break;
case 9:
index = DashMiddle(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
index = LineBack(index);
index = DashMiddle(index);
break;
}
}

void SetSize(int s)
{
size = s;
int i;

for (i = 0; i<23; i++)
{
if (disp)
free (disp);
}

for (i = 0; i < 2*size + 3; i++)
{
disp = (char*)malloc( sizeof(char)*1000);
strcpy(disp, "");
}

for (i; i<23; i++)
{
disp = NULL;
}

}

void EndLine()
{
Print();
}

private:


void Print()
{
//end the strings:
for (int i = 0; i < size*2 + 3; i++)
{
strcat(disp, "\0");
printf("%s", disp);
printf("\n");
}
}

int BlankLine(int index)
{
for (int i = 0; i < size+2; i++)
{
strcat(disp[index], " ");
}
index++;
return index;
}

int LineBackAndFront(int index)
{
for (int i = 0; i < size; i++)
{
strcat(disp[index], "|");
for (int j = 0; j < size; j++)
{
strcat(disp[index], " ");
}
strcat(disp[index], "|");
index++;
}
return index;
}

void BlankColumn()
{
for (int i = 0; i < 2*size+3; i++)
{
strcat(disp, " ");
}

}


int LineBack(int index)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size + 1; j++)
{
strcat(disp[index], " ");
}
strcat(disp[index], "|");
index++;
}
return index;
}

int LineFront(int index)
{
for (int i = 0; i < size; i++)
{
strcat(disp[index], "|");
for (int j = 0; j < size + 1; j++)
{
strcat(disp[index], " ");
}
index++;
}
return index;
}

int DashFront(int index)
{
int i;
for (i = 0; i < size; i++)
{
strcat(disp[index], "-");
}
for (i; i < size + 2; i++)
{
strcat(disp[index], " ");
}
index++;
return index;
}

int DashMiddle(int index)
{
strcat(disp[index], " ");
for (int i = 0; i < size; i++)
{
strcat(disp[index], "-");
}
strcat(disp[index], " ");
index++;
return index;
}
};


/*int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)*/
int main(int argc, char * argv)
{
char s = ' ';
int i;
int result;

LCD* myLCD = new LCD();

//get size
scanf( "%c", &s );
while (true)
{
while (s == ' ')
result = scanf( "%c", &s );

i = atoi(&s);
//check to see if it's not 10:
if (i == 1)
{
result = scanf( "%c", &s );
if (s != ' ')
{
i *=10;
i += atoi(&s);
}
}
else if (i == 0) //check for exit condition
{
result = scanf( "%c", &s );
while (s == ' ')
result = scanf( "%c", &s );
if (s == '0')
return 0;
}

if ( (i < 1) || (i > 10) )
{
printf("error: size must be between 1 and 10");
return 0;
}
myLCD->SetSize(i);

//get first char
result = scanf( "%c", &s );
while (s == ' ')
result = scanf( "%c", &s );

//get the rest of the string
int count=0;
while (s != '\n')
{
count++;
if ( (s < '0') || (s > '9'))
{
printf("error: non-numeric characters in line");
return 0;
}
myLCD->AddNumber(atoi(&s));
result = scanf( "%c", &s );
if (count > 8)
{
printf("error: number must be between 0 and 99 999 999");
return 0;
}
}
myLCD->EndLine();
//move the next line
result = scanf( "%c", &s );
}
return 0;
}
[cpp][/cpp]

regina
New poster
Posts: 4
Joined: Mon May 10, 2004 11:57 pm

Still Not accepted

Post by regina »

Hi -- can anyone tell me what's going on with my code?
Thanks...

[cpp]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

class LCD
{
private:
char* disp[23];
int size;
public:

LCD()
{
for (int i = 0; i<23; i++)
{
disp = NULL;
}
}

~LCD()
{
if (disp)
delete[] disp;
}

void AddNumber(int number)
{
int index = 0;
if (strcmp(disp[0], "") != 0) //this is the first row
{
BlankColumn();
}
switch (number)
{
//draw a zero
case 0:
index = DashMiddle(index);
index = LineBackAndFront(index);
index = BlankLine(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
break;

case 1:
index = BlankLine(index);
index = LineBack(index);
index = BlankLine(index);
index = LineBack(index);
index = BlankLine(index);
break;
case 2:
index = DashMiddle(index);
index = LineBack(index);
index = DashMiddle(index);
index = LineFront(index);
index = DashMiddle(index);
break;
case 3:
index = DashFront(index);
index = LineBack(index);
index = DashFront(index);
index = LineBack(index);
index = DashFront(index);
break;
case 4:
index = BlankLine(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
index = LineBack(index);
index = BlankLine(index);
break;
case 5:
index = DashMiddle(index);
index = LineFront(index);
index = DashMiddle(index);
index = LineBack(index);
index = DashMiddle(index);
break;
case 6:
index = DashMiddle(index);
index = LineFront(index);
index = DashMiddle(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
break;
case 7:
index = DashMiddle(index);
index = LineBack(index);
index = BlankLine(index);
index = LineBack(index);
index = BlankLine(index);
break;
case 8:
index = DashMiddle(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
break;
case 9:
index = DashMiddle(index);
index = LineBackAndFront(index);
index = DashMiddle(index);
index = LineBack(index);
index = DashMiddle(index);
break;
}
}

void SetSize(int s)
{
size = s;
int i;

for (i = 0; i<23; i++)
{
if (disp)
free (disp);
}

for (i = 0; i < 2*size + 3; i++)
{
disp = (char*)malloc( sizeof(char)*1000);
strcpy(disp, "");
}

for (i; i<23; i++)
{
disp = NULL;
}

}

void EndLine()
{
Print();
}

private:


void Print()
{
//end the strings:
for (int i = 0; i < size*2 + 3; i++)
{
strcat(disp, "\0");
printf("%s", disp);
printf("\n");
}
}

int BlankLine(int index)
{
for (int i = 0; i < size+2; i++)
{
strcat(disp[index], " ");
}
index++;
return index;
}

int LineBackAndFront(int index)
{
for (int i = 0; i < size; i++)
{
strcat(disp[index], "|");
for (int j = 0; j < size; j++)
{
strcat(disp[index], " ");
}
strcat(disp[index], "|");
index++;
}
return index;
}

void BlankColumn()
{
for (int i = 0; i < 2*size+3; i++)
{
strcat(disp, " ");
}

}


int LineBack(int index)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size + 1; j++)
{
strcat(disp[index], " ");
}
strcat(disp[index], "|");
index++;
}
return index;
}

int LineFront(int index)
{
for (int i = 0; i < size; i++)
{
strcat(disp[index], "|");
for (int j = 0; j < size + 1; j++)
{
strcat(disp[index], " ");
}
index++;
}
return index;
}

int DashFront(int index)
{
int i;
for (i = 0; i < size; i++)
{
strcat(disp[index], "-");
}
for (i; i < size + 2; i++)
{
strcat(disp[index], " ");
}
index++;
return index;
}

int DashMiddle(int index)
{
strcat(disp[index], " ");
for (int i = 0; i < size; i++)
{
strcat(disp[index], "-");
}
strcat(disp[index], " ");
index++;
return index;
}
};


/*int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)*/
int main(int argc, char * argv)
{
char s = ' ';
int i;
int result;

LCD* myLCD = new LCD();

//get size
scanf( "%c", &s );
while (true)
{
while (s == ' ')
result = scanf( "%c", &s );

i = atoi(&s);
//check to see if it's not 10:
if (i == 1)
{
result = scanf( "%c", &s );
if (s != ' ')
{
i *=10;
i += atoi(&s);
}
}
else if (i == 0) //check for exit condition
{
result = scanf( "%c", &s );
while (s == ' ')
result = scanf( "%c", &s );
if (s == '0')
{
//check for blank line:
result = scanf( "%c", &s );
while (s != '\n')
{
if (s != ' ')
{
printf("error in input line");
break;
}
result = scanf( "%c", &s );
}
return 0;
}
}

if ( (i < 1) || (i > 10) )
{
printf("error: size must be between 1 and 10");
return 0;
}
myLCD->SetSize(i);

//get first char
result = scanf( "%c", &s );
while (s == ' ')
result = scanf( "%c", &s );

//get the rest of the string
int count=0;
while (s != '\n')
{
if (count == 8)
{
printf("error: number must be between 0 and 99 999 999");
return 0;
}
bool getnewLine=true;
if ( (s < '0') || (s > '9'))
{
if (s == ' ') //if it's just a blank line at the end, ignore it
{
while (s == ' ')
result = scanf( "%c", &s );
if (s == '\n')
{
getnewLine=false;
continue;
}
}

printf("error: non-numeric characters in line");
return 0;
}
myLCD->AddNumber(atoi(&s));
count++;
if (getnewLine)
result = scanf( "%c", &s );
}
myLCD->EndLine();
//move the next line
result = scanf( "%c", &s );
}
return 0;
}

[/cpp]

GreenPenInc
Learning poster
Posts: 53
Joined: Sat May 01, 2004 9:31 pm
Contact:

Post by GreenPenInc »

I actually got mine accepted, first try. It was very gratifying.

That code above is at least twice as long as it needs to be, btw.

Hints? Consider: for a given number (like "12345") you have to print the entire top row before moving on to the top column, then the middle row, then the bottom column and finally the bottom row. Your method will thus need to accept the entire string of the number, in addition to a parameter telling the size (so it knows how much to repeat). Good luck!
_-(GPI)-_

"Finally I have freed myself from the clutches of the garbage fairy!"

Post Reply

Return to “Volume 7 (700-799)”