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

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 706 - LC-Display

Post by Obaida »

Some one please help me to get Acc.
I got wa for this problem. :cry:

Code: Select all

#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
	int s,j,k,l,lenst;
	char st[20];
	while(scanf("%d",&s)==1)
	{
		getchar();
		gets(st);
		if(st[0]=='0'&&s==0)break;
		lenst = strlen(st);
		for(j=0;j<lenst;j++)
		{
			if(st[j]=='1'||st[j]=='4')
			{
				for(k=0;k<s+2;k++)
					printf(" ");
			}
			else
			{
				printf(" ");
				for(k=0;k<s;k++)
					printf("-");
				printf(" ");
			}
			if(j!=lenst-1)printf(" ");
		}
		printf("\n");
		for(l=0;l<s;l++)
		{
			for(j=0;j<lenst;j++)
			{
				if(st[j]=='1'||st[j]=='2'||st[j]=='3'||st[j]=='7')
				{
					printf(" ");
					for(k=0;k<s;k++)
						printf(" ");
					printf("|");
				}
				else if(st[j]=='8'||st[j]=='9'||st[j]=='0'||st[j]=='4')
				{
					printf("|");
					for(k=0;k<s;k++)
						printf(" ");
					printf("|");
				}
				else
				{
					printf("|");
					for(k=0;k<s;k++)
						printf(" ");
					printf(" ");
				}
				if(j!=lenst-1)printf(" ");
			}
			printf("\n");
		}
		for(j=0;j<lenst;j++)
		{
			if(st[j]=='1'||st[j]=='7'||st[j]=='0')
			{
				for(k=0;k<s+2;k++)
					printf(" ");
			}
			else
			{
				printf(" ");
				for(k=0;k<s;k++)
					printf("-");
				printf(" ");
			}
			if(j!=lenst-1)printf(" ");
		}
		printf("\n");
		for(l=0;l<s;l++)
		{
			for(j=0;j<lenst;j++)
			{
				if(st[j]=='1'||st[j]=='3'||st[j]=='4'||st[j]=='5'||st[j]=='7'||st[j]=='9')
				{
					printf(" ");
					for(k=0;k<s;k++)
						printf(" ");
					printf("|");
				}
				else if(st[j]=='8'||st[j]=='6'||st[j]=='0')
				{
					printf("|");
					for(k=0;k<s;k++)
						printf(" ");
					printf("|");
				}
				else
				{
					printf("|");
					for(k=0;k<s;k++)
						printf(" ");
					printf(" ");
				}
				if(j!=lenst-1)printf(" ");
			}
			printf("\n");
		}
		for(j=0;j<lenst;j++)
		{
			if(st[j]=='1'||st[j]=='4'||st[j]=='7')
			{
				for(k=0;k<s+2;k++)
					printf(" ");
			}
			else
			{
				printf(" ");
				for(k=0;k<s;k++)
					printf("-");
				printf(" ");
			}
			if(j!=lenst-1)printf(" ");
		}
		printf("\n\n");
	}
	return 0;
}
try_try_try_try_&&&_try@try.com
This may be the address of success.
alirezanoori
New poster
Posts: 26
Joined: Fri Jan 02, 2009 12:41 am

Re: 706 - LC-Display

Post by alirezanoori »

WA!!!!
I've done all I could. I tested my program with all of test data I could think of and for all of test data here. I read all of posts and couldn't find anything wrong with my solution.
Please take a look at it.

Code: Select all

So many modifications. Removed.
Last edited by alirezanoori on Fri Jan 23, 2009 4:30 pm, edited 1 time in total.
alirezanoori
New poster
Posts: 26
Joined: Fri Jan 02, 2009 12:41 am

Re: 706 - LC-Display

Post by alirezanoori »

Hello? Anybody there?? :D If you can't understand my code I'm ready for some explanations!! ;)
vahid sanei
Learning poster
Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

Re: 706 - LC-Display

Post by vahid sanei »

alirezanoori wrote:Hello? Anybody there?? :D If you can't understand my code I'm ready for some explanations!! ;)
you should use 2 newline charachters ( cout<<"\n\n";) after each testcase

i get PE(peresentation error)
could you help me ?
and What`s the PE?
here is my code

Code: Select all

Removed After AC
Thanks in advance
Last edited by vahid sanei on Fri Jan 16, 2009 9:14 pm, edited 1 time in total.
Impossible says I`m possible
alirezanoori
New poster
Posts: 26
Joined: Fri Jan 02, 2009 12:41 am

Re: 706 - LC-Display

Post by alirezanoori »

vahid sanei wrote:
alirezanoori wrote:Hello? Anybody there?? :D If you can't understand my code I'm ready for some explanations!! ;)
you should use 2 newline charachters ( cout<<"\n\n";) after each testcase

i get PE(peresentation error)
could you help me ?
and What`s the PE?
here is my code

Thanks in advance
Well, I think I output two new lines after each test data. (One blank line after each).
look at the part:

Code: Select all

if(c++ != 0)
         cout << endl << endl;
Do you mean I should use two blank lines after each test data? Does this include the last line?
vahid sanei
Learning poster
Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

Re: 706 - LC-Display

Post by vahid sanei »

Well, I think I output two new lines after each test data. (One blank line after each).
look at the part:

Code: Select all

    if(c++ != 0)
             cout << endl << endl;
Do you mean I should use two blank lines after each test data? Does this include the last line?
one of your bugs is " if(c++ !=0)"
"Output a blank line after each number"
Impossible says I`m possible
alirezanoori
New poster
Posts: 26
Joined: Fri Jan 02, 2009 12:41 am

Re: 706 - LC-Display

Post by alirezanoori »

vahid sanei wrote:
one of your bugs is " if(c++ !=0)"
"Output a blank line after each number"
Well, I changed the code to something like this, but still WA:

Code: Select all

        printChars(size);
        cout << endl << endl;
vahid sanei
Learning poster
Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

Re: 706 - LC-Display

Post by vahid sanei »

Well, I changed the code to something like this, but still WA
you print a space after last digit
you should print space between two digit !!! :D it was my bug and i think is your bug too,
Impossible says I`m possible
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 706 - LC-Display

Post by Obaida »

Code: Select all

removed
Last edited by Obaida on Sun Jan 18, 2009 9:41 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
vahid sanei
Learning poster
Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

Re: 706 - LC-Display

Post by vahid sanei »

your bug is in reading inputs
try these(<space>==' ')

Code: Select all

1<space><space><space>3<space><space>
Impossible says I`m possible
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 706 - LC-Display

Post by Obaida »

Thank you a lot. I got acc. :D :D :D :D
try_try_try_try_&&&_try@try.com
This may be the address of success.
alirezanoori
New poster
Posts: 26
Joined: Fri Jan 02, 2009 12:41 am

Re: 706 - LC-Display

Post by alirezanoori »

Well, I fixed all of that. Still WA.
Here's the new code.
One thing I don't know is this:
I should print a new line after each number and print another one between cases? (One blank line between cases and a new line after each test) or I should print just a blank line between each test case.
for example:

Code: Select all

Input:
1 123
1 123
0 0

Code: Select all

Output:
bbbbb-bbb-b
bb|bbb|bbb|
bbbbb-bbb-b
bb|b|bbbbb|
bbbbb-bbb-b

bbbbb-bbb-b
bb|bbb|bbb|
bbbbb-bbb-b
bb|b|bbbbb|
bbbbb-bbb-b
EOF
or

Code: Select all

Output:
bbbbb-bbb-b
bb|bbb|bbb|
bbbbb-bbb-b
bb|b|bbbbb|
bbbbb-bbb-b

bbbbb-bbb-b
bb|bbb|bbb|
bbbbb-bbb-b
bb|b|bbbbb|
bbbbb-bbb-bEOF
Note: replace b with ' ' (space). EOF indicates end of file.
if you use VS you should see "Press any key to continue" instead of EOF.
I tried both but still WA.

Code: Select all

#include <iostream>
#include <cmath>
#include <memory>
#include <string>
using std::string;
using std::cout;
using std::endl;
using std::cin;

#define MAXW 13
#define MAXH 23
char a[MAXH][MAXW];
char arena[MAXH * 4][MAXW * 11];

int curDigit;

void AddRowCol(int num, int size)
{
    int i;
    if(num & 1)
    {
        for(i = 1; i <= size; i++)
            a[0][i] = '-';
    }

    if(num & 2)
    {
        for(i = 1; i <= size; i++)
            a[i][0] = '|';
    }

    if(num & 4)
    {
        for(i = 1; i <= size; i++)
            a[i][size + 1] = '|';
    }
    
    if(num & 8)
    {
        for(i = 1; i <= size; i++)
            a[size + 1][i] = '-';
    }

    if(num & 16)
    {
        for(i = 1; i <= size; i++)
            a[i + size + 1][0] = '|';
    }

    if(num & 32)
    {
        for(i = 1; i <= size; i++)
            a[i + size + 1][size + 1] = '|';
    }

    
    if(num & 64)
    {
        for(i = 1; i <= size; i++)
            a[2 * size + 2][i] = '-';
    }
}

void AddChar(char ch, int size)
{
    if(size <= 0)
        return;
    memset(a, ' ', sizeof a);
    switch(ch)
    {
    case '1': AddRowCol(4 + 32, size); break;
    case '2': AddRowCol(1 + 4 + 8 + 16 + 64, size); break;
    case '3': AddRowCol(1 + 4 + 8 + 32 + 64, size); break;
    case '4': AddRowCol(2 + 4 + 8 + 32, size); break;
    case '5': AddRowCol(1 + 2 + 8 + 32 + 64, size); break;
    case '6': AddRowCol(1 + 2 + 8 + 16 + 32 + 64, size); break;
    case '7': AddRowCol(1 + 4 + 32, size); break;
    case '8': AddRowCol(1 + 2 + 4 + 8 + 16 + 32 + 64, size); break;
    case '9': AddRowCol(1 + 2 + 4 + 8 + 32 + 64, size); break;
    case '0': AddRowCol(1 + 2 + 4 + 16 + 32 + 64, size); break;
    }

    for(int i = 0; i <= (size * 2 + 2); i++)
    {
        for(int j = 0; j <= (size + 1); j++)
            arena[i][j + (curDigit * (size + 2)) + curDigit] = a[i][j];
    }
    curDigit++;
}

void printChars(int size)
{
    if(size <= 0)
        return;
    int i, j;

    for(i = 0; i <= (size * 2 + 2); i++)
    {
        for(j = 0; j < ((curDigit) * (size + 2) + curDigit - 1); j++)
            cout << arena[i][j];
        if(i != (size * 2 + 2))
            cout << endl;
    }
}

int main()
{
    int size, i;
    string buffer;
    int c = 0;
    bool found;
    while(cin >> size, size)
    {
        if(c++ != 0)
            cout << endl << endl;
        memset(arena, 0, sizeof arena);
        curDigit = 0;
        getline(cin, buffer);
        found = false;
        for(i = 0; i < (int)buffer.size(); i++)
        {
            if(isdigit(buffer[i]))
            {
                found = true;
                AddChar(buffer[i], size);
            }
        }
        if(found)
            printChars(size);
    }
    return 0;
}
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 706 - LC-Display

Post by mf »

Every line in the output, including the last one, should be terminated be a newline character (\n or std::endl) - this is a general convention about text files on Unix.
alirezanoori
New poster
Posts: 26
Joined: Fri Jan 02, 2009 12:41 am

Re: 706 - LC-Display

Post by alirezanoori »

Well, as I said, I tried both ways and all got WA!
Please tell me what is wrong. I checked all possible ways for input and output. All works.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 706 - LC-Display

Post by mf »

1) Your programs outputs \0 characters instead of some spaces.
2) Problem statement says "Output a blank line after each number." That means that at the end of the output file there should be exactly two \n characters.
Post Reply

Return to “Volume 7 (700-799)”