Page 11 of 15

Re: 706 - LC-Display

Posted: Fri Dec 26, 2008 7:51 am
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;
}

Re: 706 - LC-Display

Posted: Sun Jan 04, 2009 3:12 pm
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.

Re: 706 - LC-Display

Posted: Fri Jan 09, 2009 9:20 pm
by alirezanoori
Hello? Anybody there?? :D If you can't understand my code I'm ready for some explanations!! ;)

Re: 706 - LC-Display

Posted: Sun Jan 11, 2009 2:12 pm
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

Re: 706 - LC-Display

Posted: Mon Jan 12, 2009 1:36 pm
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?

Re: 706 - LC-Display

Posted: Mon Jan 12, 2009 3:14 pm
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"

Re: 706 - LC-Display

Posted: Wed Jan 14, 2009 12:42 pm
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;

Re: 706 - LC-Display

Posted: Fri Jan 16, 2009 9:17 pm
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,

Re: 706 - LC-Display

Posted: Sat Jan 17, 2009 8:18 am
by Obaida

Code: Select all

removed

Re: 706 - LC-Display

Posted: Sat Jan 17, 2009 4:47 pm
by vahid sanei
your bug is in reading inputs
try these(<space>==' ')

Code: Select all

1<space><space><space>3<space><space>

Re: 706 - LC-Display

Posted: Sun Jan 18, 2009 9:42 am
by Obaida
Thank you a lot. I got acc. :D :D :D :D

Re: 706 - LC-Display

Posted: Fri Jan 23, 2009 4:27 pm
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;
}

Re: 706 - LC-Display

Posted: Fri Jan 23, 2009 7:13 pm
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.

Re: 706 - LC-Display

Posted: Sun Jan 25, 2009 4:53 pm
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.

Re: 706 - LC-Display

Posted: Sun Jan 25, 2009 5:33 pm
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.