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

t_sergiu
New poster
Posts: 12
Joined: Sun Mar 02, 2008 6:18 am

Post by t_sergiu »

adding two new lines at the end of all output gave me AC as well, while only putting one new line didnt

assasin
New poster
Posts: 7
Joined: Wed Feb 13, 2008 3:59 pm
Location: Dhaka,Bangladesh

706

Post by assasin »

Here is my code

Code: Select all

#include <stdio.h>

char sign0[25][15];
char sign1[25][15];
char sign2[25][15];
char sign3[25][15];
char sign4[25][15];
char sign5[25][15];
char sign6[25][15];
char sign7[25][15];
char sign8[25][15];
char sign9[25][15];
//s+2 rows and 2*s+3 columns
//s is at most 10

void print0(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
			if( (j != 0 && j != size + 1 ) && ( i == 0 || i == size * 2 + 2 ) )
				sign0[i][j] = '-';
			else if( ( j == 0 || j == size + 1 ) && ( i != 0 && i != size + 1 && i != 2 * size + 2 ) )
				sign0[i][j] = '|';
			else sign0[i][j] = ' ';
				
		}
	}
}

void print1(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
	
			if( ( j == size + 1 ) && ( i != 0 && i != size + 1 && i != 2 * size + 2 ) )
				sign1[i][j] = '|';
			else sign1[i][j] = ' ';
				
		}
	}
}
void print2(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
			if( (j != 0 && j != size + 1 ) && ( i == 0 || i == size * 2 + 2 || i == size + 1) )
				sign2[i][j] = '-';
			else if( ( j == size + 1 ) && ( i != 0 && i < (size + 1) ) )
				sign2[i][j] = '|';
			else if( ( j == 0) && ( i != (2 * size + 2) && i > (size + 1) ) )
				sign2[i][j] = '|';
			else sign2[i][j] = ' ';
				
		}
	}
}

void print3(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
			if( (j != 0 && j != size + 1 ) && ( i == 0 || i == size * 2 + 2 || i == size + 1) )
				sign3[i][j] = '-';
			else if( ( j == size + 1 ) && ( i != 0 && i != size + 1 && i != 2 * size + 2 ) )
				sign3[i][j] = '|';
			else sign3[i][j] = ' ';
				
		}
	}
}

void print4(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
	
			if( ( j == size + 1 ) && ( i != 0 && i != size + 1 && i != 2 * size + 2 ) )
				sign4[i][j] = '|';
			else if ( ( j == 0 ) && ( i != 0 && i < size + 1 ) )	
				sign4[i][j] = '|';
			else if( (j != 0 && j != size + 1) && ( i == size + 1) )
				sign4[i][j] = '-';
			else sign4[i][j] = ' ';
				
		}
	}
}

void print5(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
			if( (j != 0 && j != size + 1 ) && ( i == 0 || i == size * 2 + 2 || i == size + 1) )
				sign5[i][j] = '-';
			else if( ( j == 0 ) && ( i != 0 && i < size + 1 ) )
				sign5[i][j] = '|';
			else if( ( j == size + 1 ) && ( i != 2 * size + 2 && i > size + 1 ) )
				sign5[i][j] = '|';
			else sign5[i][j] = ' ';
				
		}
	}
}

void print6(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
			if( (j != 0 && j != size + 1 ) && ( i == 0 || i == size * 2 + 2 || i == size + 1) )
				sign6[i][j] = '-';
			else if( ( j == 0 ) && ( i != 0 && i != size + 1 && i != 2 * size + 2 ) )
				sign6[i][j] = '|';
			else if( (j == size + 1 ) && ( i != 2 * size + 2 && i > size + 1 ) )
				sign6[i][j] = '|';
			else sign6[i][j] = ' ';
				
		}
	}
}

void print7(int size){

	int i,j;
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
			if( (j != 0 && j != size + 1 ) && ( i == 0) )
				sign7[i][j] = '-';
			else if( ( j == size + 1 ) && ( i != 0 && i != size + 1 && i != 2 * size + 2 ) )
				sign7[i][j] = '|';
			else sign7[i][j] = ' ';
				
		}
	}
}

void print8(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
			if( (j != 0 && j != size + 1 ) && ( i == 0 || i == size * 2 + 2 || i == size + 1) )
				sign8[i][j] = '-';
			else if( ( j == 0 || j == size + 1 ) && ( i != 0 && i != size + 1 && i != 2 * size + 2 ) )
				sign8[i][j] = '|';
			else sign8[i][j] = ' ';
				
		}
	}
}
void print9(int size){
	int i ,j;
		
	for(i = 0 ; i < size * 2 + 3 ; i++ ){
		
		for( j = 0 ; j < size + 2 ; j++ ){
			if( (j != 0 && j != size + 1 ) && ( i == 0 || i == size * 2 + 2 || i == size + 1) )
				sign9[i][j] = '-';
			else if( ( j == size + 1 ) && ( i != 0 && i != size + 1 && i != 2 * size + 2 ) )
				sign9[i][j] = '|';
			else if( (j == 0 ) && ( i != 0 && i < size + 1 ) )
				sign9[i][j] = '|';
			else sign9[i][j] = ' ';
				
		}
	}
}


void print(char num[25][15],int row,int size){
	
	int i;

	for(i = 0 ; i < size + 2 ; i++ )
		printf("%c",num[row][i]);
}

int main(){
	int size , input;
	int temp , count = 0;
	int array[10];
	int arraysize = 0;	

	while(scanf("%d%d",&size,&input)){
		if(size == 0 && input == 0)
			break;
		if(count != 0)
			printf("\n");
		
		count++;
		print0(size);
		print1(size);
		print2(size);
		print3(size);
		print4(size);
		print5(size);
		print6(size);
		print7(size);
		print8(size);
		print9(size);

		arraysize = 0;
		do{

			temp = input % 10;
			input = input/10;
			array[arraysize] = temp;
			arraysize++;		
		}while(input != 0);		
		
		for(int i = 0 ; i < 2 * size + 3 ; i++){		

			for(int j = arraysize - 1 ; j >= 0 ; j-- ){
			
				if(array[j] == 1)
					print(sign1,i,size);
				else if(array[j] == 0)
					print(sign0,i,size);				
				else if(array[j] == 3)
					print(sign3,i,size);
				else if(array[j] == 2)
					print(sign2,i,size);
				else if(array[j] == 4)
					print(sign4,i,size);
				else if(array[j] == 5)
					print(sign5,i,size);
				else if(array[j] == 6)
					print(sign6,i,size);
				else if(array[j] == 7)
					print(sign7,i,size);
				else if(array[j] == 8)
					print(sign8,i,size);
				else
					print(sign9,i,size);
				if( j != 0)
					printf(" ");
			}
			printf("\n");
		}
	
	}

	return 0;
}

I have not found any reason of getting PE
Can anyone find it out for me?
Thank You

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

1. Read this

2. Search before post.

3. Don't open new thread if related thread exists.

sdx
New poster
Posts: 5
Joined: Wed Apr 30, 2008 2:26 pm

Re: 706 - LC-Display - WA

Post by sdx »

Hi,

The judge and I dont seem to be getting along very well :( Guys please see if you can help me. Here is my program...

Code: Select all

//LCD Display. UVAID: 706
//Status:WA
#if defined ONLINE_JUDGE || defined LCD_DISPLAY2

#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool isOddLine(int line)
{
	return line == 1 || line == 3;
}

//NOTE: Line <- [0,5) always
void printDigit(int scale, int digit, int line)
{
	if(digit>9)
		return;

	//0,1,2,3,4,5,6,7,8,9
	//height: 2*s+3
	//width: s+2
	//where s is the number of chars per segment
	static const int minWidth  = 1+2;//s=1
	static const int minHeight = 2*1+3;//s=1
	static const int numDigits = 10;
	static const char bitmap[numDigits][minHeight][minWidth+1] = { //Accomodate the terminating NULL char in the following strings.
		{
			{" - "},
			{"| |"},
			{"   "},
			{"| |"},
			{" - "}
		},
		{
			{"   "},
			{"  |"},
			{"   "},
			{"  |"},
			{"   "}
		},
		{
			{" - "},
			{"  |"},
			{" - "},
			{"|  "},
			{" - "}
		},
		{
			{" - "},
			{"  |"},
			{" - "},
			{"  |"},
			{" - "}
		},
		{
			{"   "},
			{"| |"},
			{" - "},
			{"  |"},
			{"   "}
		},
		{
			{" - "},
			{"|  "},
			{" - "},
			{"  |"},
			{" - "}
		},
		{
			{" - "},
			{"|  "},
			{" - "},
			{"| |"},
			{" - "}
		},
		{
			{" - "},
			{"  |"},
			{"   "},
			{"  |"},
			{"   "}
		},
		{
			{" - "},
			{"| |"},
			{" - "},
			{"| |"},
			{" - "}
		},
		{
			{" - "},
			{"| |"},
			{" - "},
			{"  |"},
			{" - "}
		}
	};

	//void printDigit(int scale, int digit, int line)

	//0,1,2,3,4,5,6,7,8,9
	//height: 2*s+3
	//width: s+2
	//where s is the number of chars per segment
	

	//Errorlog
	//1. Assumed that horizontal scaling applied only to even rows.


	for(int x = 0; x < minWidth; x++)
	{
		if(x == 1)
		{
			for(int i=0; i<scale; i++)
			{
				cout<<bitmap[digit][line][x];
			}
		}
		else
		{
			cout<<bitmap[digit][line][x];
		}
	}
}


void printLine(int scale, string number, int line)
{
	size_t i=0;
	//Print out the specified line for all the digits.
	for(; i<number.size()-1; i++)
	{
		printDigit(scale, number[i]-'0', line);
			cout<<" ";
	}
	//print the last digit
	printDigit(scale, number[i]-'0', line);
	cout<<endl;
}

void printNumber(int scale, string number)
{
	//Print the digits line by line.
	for(int line=0; line<2*1+3; line++)
	{
		if(isOddLine(line)) //Repeat odd lines 'scale' number of times.
		{
			for(int i = 0; i<scale; i++)
			{
				printLine(scale, number, line);
			}
		}
		else
		{
			printLine(scale, number, line);
		}
	}
}

void LcdDisplay()
{
	int scale=0;
	string number;
	cin>>scale>>number;
	while(scale != 0 && number != "0")
	{
		printNumber(scale, number);

		cin>>scale>>number;

		if(scale != 0 && number != "0")
			cout<<endl;
	}
}


int main()
{
	LcdDisplay();
	return 0;
}
#endif


I cant help but think the judge is being anal and giving a WA instead of a PE.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 706 - LC-Display - WA

Post by Jan »

There should be a blank line after every case.
Ami ekhono shopno dekhi...
HomePage

sdx
New poster
Posts: 5
Joined: Wed Apr 30, 2008 2:26 pm

Re: 706 - LC-Display - WA

Post by sdx »

Hi Jan,

I think I have put a blank line in between each output as asked for in the problem. Here is the sample output for the input given in the problem...
Image
(see http://bp3.blogger.com/_VTIyYPvHp_0/SB6 ... -h/LCD.JPG )

Note: The "Press any key to continue" text is not part of the output.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 706 - LC-Display - WA

Post by Jan »

There should be a blank line before 'Press any key to continue'. Read the description again, I have already mentioned it.
Ami ekhono shopno dekhi...
HomePage

sdx
New poster
Posts: 5
Joined: Wed Apr 30, 2008 2:26 pm

Re: 706 - LC-Display - WA

Post by sdx »

Ok I tried that but still no luck. Here is the changed code... (I changed only a single line of code)

Code: Select all

//LCD Display. UVAID: 706
//Status:Not Submitted

#if defined ONLINE_JUDGE || defined LCD_DISPLAY2

#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool isOddLine(int line)
{
	return line == 1 || line == 3;
}

//NOTE: Line <- [0,5) always
void printDigit(int scale, int digit, int line)
{
	if(digit>9)
		return;

	//0,1,2,3,4,5,6,7,8,9
	//height: 2*s+3
	//width: s+2
	//where s is the number of chars per segment
	static const int minWidth  = 1+2;//s=1
	static const int minHeight = 2*1+3;//s=1
	static const int numDigits = 10;
	static const char bitmap[numDigits][minHeight][minWidth+1] = { //Accomodate the terminating NULL char in the following strings.
		{
			{" - "},
			{"| |"},
			{"   "},
			{"| |"},
			{" - "}
		},
		{
			{"   "},
			{"  |"},
			{"   "},
			{"  |"},
			{"   "}
		},
		{
			{" - "},
			{"  |"},
			{" - "},
			{"|  "},
			{" - "}
		},
		{
			{" - "},
			{"  |"},
			{" - "},
			{"  |"},
			{" - "}
		},
		{
			{"   "},
			{"| |"},
			{" - "},
			{"  |"},
			{"   "}
		},
		{
			{" - "},
			{"|  "},
			{" - "},
			{"  |"},
			{" - "}
		},
		{
			{" - "},
			{"|  "},
			{" - "},
			{"| |"},
			{" - "}
		},
		{
			{" - "},
			{"  |"},
			{"   "},
			{"  |"},
			{"   "}
		},
		{
			{" - "},
			{"| |"},
			{" - "},
			{"| |"},
			{" - "}
		},
		{
			{" - "},
			{"| |"},
			{" - "},
			{"  |"},
			{" - "}
		}
	};

	//void printDigit(int scale, int digit, int line)

	//0,1,2,3,4,5,6,7,8,9
	//height: 2*s+3
	//width: s+2
	//where s is the number of chars per segment
	

	//Errorlog
	//1. Assumed that horizontal scaling applied only to even rows.


	for(int x = 0; x < minWidth; x++)
	{
		if(x == 1)
		{
			for(int i=0; i<scale; i++)
			{
				cout<<bitmap[digit][line][x];
			}
		}
		else
		{
			cout<<bitmap[digit][line][x];
		}
	}
}


void printLine(int scale, string number, int line)
{
	size_t i=0;
	//Print out the specified line for all the digits.
	for(; i<number.size()-1; i++)
	{
		printDigit(scale, number[i]-'0', line);
			cout<<" ";
	}
	//print the last digit
	printDigit(scale, number[i]-'0', line);
	cout<<endl;
}

void printNumber(int scale, string number)
{
	//Print the digits line by line.
	for(int line=0; line<2*1+3; line++)
	{
		if(isOddLine(line)) //Repeat odd lines 'scale' number of times.
		{
			for(int i = 0; i<scale; i++)
			{
				printLine(scale, number, line);
			}
		}
		else
		{
			printLine(scale, number, line);
		}
	}
}

void LcdDisplay()
{
	int scale=0;
	string number;
	cin>>scale>>number;
	while(scale != 0 && number != "0")
	{
		printNumber(scale, number);

		cin>>scale>>number;

		//if(scale != 0 && number != "0") //CHANGED!!!
			cout<<endl;
	}
}


int main()
{
	LcdDisplay();
	return 0;
}
#endif

takohwank
New poster
Posts: 4
Joined: Thu May 15, 2008 1:28 pm

Re: 706 - LC-Display

Post by takohwank »

hi, i still don't understand why my code got PE.

can anybody help me? (thanx before :D )

here is my code :

Code: Select all

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

int main(){
	char data[15];
	int n,i,j,c,size;

	scanf("%d %s",&n,data);
	while(n!=0 || strcmp(data,"0")!=0){
		size = (n+1)*2 + 1;

		for(i=0;i<size;i++){
			for(j=0;data[j]!='\0';j++){
				if(i == 0) {
					printf(" ");
					if(data[j] == '1' || data[j] == '4'){
						for(c=0;c<n;c++) printf(" ");
					}else{
						for(c=0;c<n;c++) printf("-");
					}
					printf(" ");
				}else if (i>0 && i<n+1){
					if(data[j] == '5' || data[j] == '6'){
						printf("|");
						for(c=0;c<n+1;c++) printf(" ");
					}else if (data[j] == '1' || data[j] == '2' || data[j] == '3' || data[j] == '7'){
						for(c=0;c<n+1;c++) printf(" ");
						printf("|");
					}else {
						printf("|");
						for(c=0;c<n;c++) printf(" ");
						printf("|");
					}
				}else if (i == (n+1)){
					printf(" ");
					if(data[j] == '1' || data[j] == '7' || data[j] == '0'){
						for(c=0;c<n;c++) printf(" ");
					}else{
						for(c=0;c<n;c++) printf("-");
					}
					printf(" ");
				}else if (i>(n+1) && i<(n+1)*2){
					if(data[j] == '2'){
						printf("|");
						for(c=0;c<n+1;c++) printf(" ");
					}else if (data[j] == '1' || data[j] == '3' || data[j] == '4' || data[j] == '5' || data[j] == '7' || data[j] == '9'){
						for(c=0;c<n+1;c++) printf(" ");
						printf("|");
					}else {
						printf("|");
						for(c=0;c<n;c++) printf(" ");
						printf("|");
					}
				}else if (i == (n+1)*2){
					printf(" ");
					if(data[j] == '1' || data[j] == '4' || data[j] == '7'){
						for(c=0;c<n;c++) printf(" ");
					}else{
						for(c=0;c<n;c++) printf("-");
					}
					printf(" ");
				}
				printf(" ");
			}
			printf("\n");
		}

		scanf("%d %s",&n,data);
		if (n!=0 || strcmp(data,"0")!=0) printf("\n");
	}

	return 0;
}

takohwank
New poster
Posts: 4
Joined: Thu May 15, 2008 1:28 pm

Re: 706 - LC-Display

Post by takohwank »

no body here??
help please...

i still can't get AC..
the judge keep give me PE..

mido_fcis
New poster
Posts: 1
Joined: Mon Jun 16, 2008 6:33 pm

Re: 706 - LC-Display

Post by mido_fcis »

thx for all this instructions , I did all wat u said and I compared my output with an accepted code , using fstream and I highlighted them , they where typical not even a change in white space ,, and the accepted code don process a leading zero , which mean it is not tested by Judge , ok now wat is the problem here in that semi perfect code ??? plz fast answer , am losing my nerves and Iam gonna Suicide !!! :evil: :evil:
and thx for advance who will matter my reply :) :)

Code: Select all

#include <iostream>
using namespace std;


const int arr[10][5]={ { 1,3,0,3,1 } , { 0,1,0,1,0} , { 1,1,1,2,1} , { 1,1,1,1,1} , { 0,3,1,1,0 } , { 1,2,1,1,1 } , { 1,2,1,3,1 } ,{ 1,1,0,1,0 },{ 1,3,1,3,1 },{ 1,3,1,1,1 } };
short n[8];	//numbers enterd by users
short s;		//size of font
short num;	//number of numbers to be draw
//////////////////////////////////////////
void v_draw(int);
void h_draw(int);
void seperate(int);
//////////////////////////////////////////

int main()
{
	int numb;
	while(cin>>s>>numb && ( !(s==0 && numb==0) ) )
	{
		seperate(numb);
		h_draw(0);
		v_draw(1);
		h_draw(2);
		v_draw(3);
		h_draw(4);
		cout<<endl;
		
	}
	return 0;
}

	
void v_draw(int lvl)///draw vertical lines or lvls
{

	for (int k=0;k<s;k++)
	{
		for(int i=num-1;i>=0;i--)
		{
			
			if(arr[n[i]][lvl] == 0)
			{
				for (int j=0;j<s+2;j++)
				cout<<" ";
			}
	
			else if(arr[n[i]][lvl] == 1)
			{	
			
				for (int j=1;j<s+2;j++)
				cout<<" ";

				cout<<"|";
	
			}

			else if(arr[n[i]][lvl] == 2)
			{
				cout<<"|";

				for (int j=1;j<s+2;j++)
				cout<<" ";
			
			}
		
			else if(arr[n[i]][lvl] == 3)
			{
				cout<<"|";

				for (int j=2;j<s+2;j++)
				cout<<" ";
	
				cout<<"|";
			}
			if ( i!=0 )cout<<" ";
		}	
		cout<<endl;
	}
}


void h_draw(int lvl)///draw horizontal lines or lvls
{
	for(int i=num-1;i>=0;i--)
	{
	
		if( arr[n[i]][lvl]==0 )
		{
			cout<<" ";
			for(int j=0;j<s;j++)
			{
				cout<<" ";
			}
			cout<<" ";
		}
		else if( arr[n[i]][lvl]==1)
		{
			cout<<" ";
			for(int j=0;j<s;j++)
			{
				cout<<"-";
			}
			cout<<" ";
		}
		if( i!=0 )cout<<" ";
	}
	cout<<endl;

}

void seperate(int mynum)
{
	int numb;
	int factor=1,temp=mynum;
	num=0;
	while(temp!=0)
	{
		num++;
		temp/=10;
	}
	
	for(int i=0;true;i++)
	{
		numb=mynum;
		numb/=10;
		numb*=10;
		n[i]=(mynum-numb);
		mynum/=10;
		if(numb==0)break;
		
	}
}

bam
New poster
Posts: 1
Joined: Fri Oct 03, 2008 11:59 am
Location: Moscow,Russia
Contact:

Re: 706 - LC-Display

Post by bam »

Hello! Please tell me why I got TLE????
It doesn't work only when n>=100 000 000(more than 8 digits). But it isn't in task.

Code: Select all

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

using namespace std;

int main(){
	int s;
	while(scanf("%d",&s) && s!=0){
		char n[8];
		char ch;
		int k=0;
		getc(stdin);
		while((ch = getc(stdin)) && (ch != '\n')){
			n[k] = ch;
			k++;
		}
		////////////////////////////////////////
		struct number{
			bool t,
				tl,
				tr,
				m,
				bl,
				br,
				b;
		};
		number d[10]; //numbers from 0 to 9
		memset(d,1,sizeof(d));
		// 0
		d[0].m = 0;
		// 1
		d[1].t = 0;
		d[1].tl = 0;
		d[1].m = 0;
		d[1].bl = 0;
		d[1].b = 0;
		// 2
		d[2].tl = 0;
		d[2].br = 0;
		// 3
		d[3].tl = 0;
		d[3].bl = 0;
		// 4
		d[4].t = 0;
		d[4].bl = 0;
		d[4].b = 0;
		// 5
		d[5].tr = 0;
		d[5].bl = 0;
		// 6
		d[6].tr = 0;
		// 7
		d[7].tl = 0;
		d[7].m = 0;
		d[7].bl = 0;
		d[7].b = 0;
		// 9
		d[9].bl = 0;
		////////////////////////////////////
		for(int q=0;q<2*s+3;q++){
			if(q==0 || q==(s+1) || q==(2*s+2))
				for(int i=0;i<k;i++){
					printf(" ");
					for(int j=0;j<s;j++)
						if((d[n[i]-'0'].t && q==0) || (d[n[i]-'0'].m && q==(s+1)) || 
							(d[n[i]-'0'].b && q==(2*s+2)))
							printf("-");
						else
							printf(" ");
					printf(" ");
					if(i==k-1)
						printf("\n");
					else
						printf(" ");
				}
			else
				for(int i=0;i<k;i++){
					if((d[n[i]-'0'].tl && q<(s+1)) || (d[n[i]-'0'].bl && q>(s+1)))
						printf("|");
					else
						printf(" ");
					for(int j=0;j<s;j++)
						printf(" ");
					if((d[n[i]-'0'].tr && q<(s+1)) || (d[n[i]-'0'].br && q>(s+1)))
						printf("|");
					else
						printf(" ");
					if(i==k-1)
						printf("\n");
					else
						printf(" ");
				}
		}
		printf("\n");
	}
	return 0;
}

gugajansen
New poster
Posts: 1
Joined: Sat Nov 08, 2008 1:51 am

Re: 706 - LC-Display

Post by gugajansen »

I just don't know why I got RE in this question :cry:

I consider blank lines on input, s and n out of the specification limit. I also tried a great test case, and it works :roll:
can someone help me? I'm desperate

here's my code:

Code: Select all

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	static final int ZERO = 48;
    static String result = "";
    static byte pow;
    static final String separator = System.getProperty("line.separator");
    static final boolean[][] numbers = 
    	{/*zero*/{true,true,true,false,true,true,true},/*one*/{false,false,true,false,false,false,true},
    	/*two*/{false,true,true,true,true,true,false},/*three*/{false,true,true,true,false,true,true}, 
    	/*four*/{true,false,true,true,false,false,true},/*five*/{true,true,false,true,false,true,true},
    	/*six*/{true,true,false,true,true,true,true},/*seven*/{false,true,true,false,false,false,true}, 
    	/*eight*/{true,true,true,true,true,true,true},/*nine*/{true,true,true,true,false,true,true}};
   
    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        boolean firsttest = true;
        
        char[] number;
       
        try {
        	while (true){
        		String line = in.readLine();
        		
        		if (!line.equals("")){
        			String[] tokens = line.split(" ");
        			pow = Byte.parseByte(tokens[0]);
        			number = tokens[1].toCharArray();
        			
        			if (pow != 0 || !tokens[1].equals("0")){
                        if (firsttest) firsttest = false;
                        else result += separator;
                        
                        boolean last_number = false;
                        byte[] figures = getFigures(number);
                        
                        // first line
                        for (int i = 0; i < figures.length; i++){
                        	if (i == figures.length - 1) last_number = true;
                        	printLine(last_number, figures[i], 1);
                        }
                        // second line
                        for (int j = 0; j < pow; j++){
                            last_number = false;
        	                for (int i = 0; i < figures.length; i++){
        	                	if (i == figures.length - 1) last_number = true;
        	                	printColumn(last_number, figures[i], 0, 2);
        	                }
                        }
                        last_number = false;
                        // third line
                        for (int i = 0; i < figures.length; i++){
                        	if (i == figures.length - 1) last_number = true;
                        	printLine(last_number, figures[i], 3);
                        }
                        // forth line
                        for (int j = 0; j < pow; j++){
                            last_number = false;
        	                for (int i = 0; i < figures.length; i++){
        	                	if (i == figures.length - 1) last_number = true;
        	                	printColumn(last_number, figures[i], 4, 6);
        	                }
                        }
                        last_number = false;
                        // fifth line
                        for (int i = 0; i < figures.length; i++){
                        	if (i == figures.length - 1) last_number = true;
                        	printLine(last_number, figures[i], 5);
                        }
                        
                        System.out.print(result);
                        result = "";
        			} else break;
        		}
        	}
        	in.close();
        } catch (IOException e){}        	
    }
    
    static byte[] getFigures(char[] number){
    	byte[] figures = new byte[number.length];
    	for (int i = 0; i < number.length; i++)
    		figures[i] = (byte) (number[i] - ZERO);
    	return figures;
    }
    
    static void printLine(boolean last_number, byte number, int number_index){
    	result += " ";
    	for (int j = 0; j < pow; j++)
    		if (numbers[number][number_index]) result += "-";
    		else result += " ";
    	result += " ";
    	if (last_number) result += separator;
    	else result += " ";
    }
    
    static void printColumn(boolean last_number, byte number, int n_index1, int n_index2){
		if (numbers[number][n_index1]) result += "|";
		else result += " ";
		for (int j = 0; j < pow; j++) result += " ";
		if (numbers[number][n_index2]) result += "|";
		else result += " ";
		if (last_number) result += separator;
		else result += " ";
    }
}
sorry for my poor english

sereth
New poster
Posts: 1
Joined: Sun Dec 21, 2008 5:28 am

Re: 706 - LC-Display

Post by sereth »

Perhaps someone would be willing to help me figure out why I'm receiving a Presentation Error on this problem? As far as I can tell, the output is correct and matches the test cases available. Specifically, I've checked:
  • No extra blanks at the end of lines
  • All digits are padded with necessary spaces to fill out the full width
  • Newline after each case (adding a second newline after the last case as some have suggested still results in a PE)
  • Leading zeros are displayed (stripping leads at a WA result)
Are there any other special cases I may not be seeing? Thanks in advance for your help.

Code: Select all

#include <iostream>
#include <string>
#include <vector>

#ifdef ONLINE_JUDGE
#define SPACER ' '
#else
#define SPACER '.'
#endif

typedef enum { SegmentUpperLeft, SegmentLowerLeft, SegmentUpperRight, SegmentLowerRight,
               SegmentTop, SegmentMiddle, SegmentBottom, SegmentUpperVertical,
               SegmentLowerVertical} Segments;

// On/off states for each digit.  Order is upper left, lower left, upper right,
// lower right, top, center, bottom.
const int ledStates[10][7] = { {1, 1, 1, 1, 1, 0, 1}, // 0
                               {0, 0, 1, 1, 0, 0, 0}, // 1
                               {0, 1, 1, 0, 1, 1, 1}, // 2
                               {0, 0, 1, 1, 1, 1, 1}, // 3
                               {1, 0, 1, 1, 0, 1, 0}, // 4
                               {1, 0, 0, 1, 1, 1, 1}, // 5
                               {1, 1, 0, 1, 1, 1, 1}, // 6
                               {0, 0, 1, 1, 1, 0, 0}, // 7
                               {1, 1, 1, 1, 1, 1, 1}, // 8
                               {1, 0, 1, 1, 1, 1, 1} }; // 9

std::string writeHorizontal(std::vector<int>& digits, Segments seg, int size)
{
   std::string output = "";

   for (int i = 0; i < digits.size(); i++)
   {
      output += SPACER;
      for (int j = 0; j < size; j++)
      {
         if (ledStates[digits[i]][seg])
            output += "-";
         else
            output += SPACER;
      }
      output = output + SPACER + SPACER;
   }
   output[output.size() - 1] = '\n';
   return output;
}

std::string writeVertical(std::vector<int>& digits, Segments seg, int size)
{
   std::string output = "";
   std::string spacer = "";
   std::string line = "";
   for (int i = 0; i < size; i++)
      spacer += SPACER;

   for (int j = 0; j < digits.size(); j++)
   {
      switch (seg)
      {
         case SegmentUpperVertical:
            if (ledStates[digits[j]][SegmentUpperLeft])
               line += "|";
            else
               line += SPACER;
            line += spacer;
            if (ledStates[digits[j]][SegmentUpperRight])
               line += "|";
            else
               line += SPACER;
            line += SPACER;
            break;
         case SegmentLowerVertical:
            if (ledStates[digits[j]][SegmentLowerLeft])
               line += "|";
            else
               line += SPACER;
            line += spacer;
            if (ledStates[digits[j]][SegmentLowerRight])
               line += "|";
            else
               line += SPACER;
            line += SPACER;
            break;
         default:
            break;
      }
   }
   line[line.size() - 1] = '\n';

   for (int i = 0; i < size; i++)
      output += line;

   return output;
}

int main(int argc, char *argv[])
{
   int size;
   int numDigits;
   std::string display;
   std::vector<int> digits;

   std::cin >> size >> display;
   while (size != 0)
   {
      // Split the digits into the digits array
      numDigits = display.size();
      digits.clear();
      for (int i = 0; i < numDigits; i++)
      {
         if ((display[i] >= '0') && (display[i] <= '9'))
               digits.push_back(static_cast<int>(display[i] - '0'));
      }

      std::cout << writeHorizontal(digits, SegmentTop, size);
      std::cout << writeVertical(digits, SegmentUpperVertical, size);
      std::cout << writeHorizontal(digits, SegmentMiddle, size);
      std::cout << writeVertical(digits, SegmentLowerVertical, size);
      std::cout << writeHorizontal(digits, SegmentBottom, size);
      std::cout << '\n';

      std::cin >> size >> display;
   }
}

tzongshiuan
New poster
Posts: 1
Joined: Tue Dec 23, 2008 6:00 am

Re: 706 - LC-Display

Post by tzongshiuan »

import java.io.*;
import java.util.*;

class Main implements Runnable{
static String ReadLn(int maxLength){ // utility function to read from stdin,
// Provided by Programming-challenges, edit for style only
byte line[] = new byte [maxLength];
int length = 0;
int input = -1;
try{
while (length < maxLength){//Read untill maxlength
input = System.in.read();
if ((input < 0) || (input == '\n')) break; //or untill end of line ninput
line [length++] += input;
}

if ((input < 0) && (length == 0)) return null; // eof
return new String(line, 0, length);
}catch (IOException e){
return null;
}
}

public static void main(String args[]) // entry point from OS
{
Main myWork = new Main(); // Construct the bootloader
myWork.run(); // execute
}

public void run() {
new myStuff().run();
}
}

class myStuff implements Runnable{
static int a, b; //claim class variable
static int index=0,i,j,dig_size,length,temp; //index????output?num???????field
//static List list = new ArrayList();
static String output[] = new String[15000];
static char lcd[][] = new char[200][200];
static String s;
static char digit[] = new char[15];

public void run(){
// Your program here
StringTokenizer st;

for (i=0 ; i<200 ; i++){ //!!!?????????0
for (j=0 ; j<200 ; j++){
lcd[j] = '0';
}
}

/*fuction start*/
while (true){
for (i=0 ; i<200 ; i++){ //!!!?????????0
for (j=0 ; j<200 ; j++){
lcd[j] = '0';
}
}

s=Main.ReadLn(255);
st = new StringTokenizer(s);
a = Integer.parseInt(st.nextToken());
s = st.nextToken();
length = s.length();
for (i=0 ; i<length ; i++){
digit = s.charAt(i);
}
b = Integer.parseInt(s);

if (a==0 && b==0){
output();
break;
}

if ( a>=11 || length>=11 || length<=0){ //range of a and b
System.out.println("Wrong range,please retry!");
break;
}

if (a != 0){ //??????a?0
/*main fuction*/
field();

s = ""; //blank line between cases
output[index] = s;
index++;
}
}
}

public void field(){
/*trans integer to LCD*/
for (i=0 ; i<length ; i++){
switch(digit){
case '0':
digit_0();
break;
case '1':
digit_1();
break;
case '2':
digit_2();
break;
case '3':
digit_3();
break;
case '4':
digit_4();
break;
case '5':
digit_5();
break;
case '6':
digit_6();
break;
case '7':
digit_7();
break;
case '8':
digit_8();
break;
case '9':
digit_9();
break;
default:
System.out.println("Fuck you mother!!!");
break;
}
}
for (i=0 ; i<2*a+3 ; i++){
s = "";
for(j=0 ; j<(a+3)*length-1 ; j++){
if (lcd[j]=='0')
s += " ";
else if (lcd[j] == '-')
s += "-";
else
s += "|";
}
output[index] = s;
index++;
}
}

public void output(){ //????? 0 0???output
/*to test output lcd[][]*/
/* for (i=0 ; i<15 ; i++){
for (j=0 ; j<20 ; j++){
System.out.print(lcd[j]);
}
System.out.println("");
}
*/
for (i=0 ; i<index-2 ; i++){
System.out.println(output);
}
System.out.println(output[index-2]);
}

/*traslate 0~9 fuction*/
/*(a+3)*i is horizontal dX*/
public void digit_0(){
for (j=0 ; j<a ; j++){
lcd[0][1+j+(a+3)*i] = '-'; //?
lcd[2*a+2][1+j+(a+3)*i] = '-';//?
lcd[1+j][0+(a+3)*i] = '|';//??
lcd[1+j][a+1+(a+3)*i] = '|';//??
lcd[2+a+j][0+(a+3)*i] = '|';//??
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}

public void digit_1(){
for (j=0 ; j<a ; j++){
lcd[1+j][a+1+(a+3)*i] = '|';//??
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}

public void digit_2(){
for (j=0 ; j<a ; j++){
lcd[0][1+j+(a+3)*i] = '-'; //?
lcd[2*a+2][1+j+(a+3)*i] = '-';//?
lcd[1+j][a+1+(a+3)*i] = '|';//??
lcd[a+1][1+j+(a+3)*i] = '-';//?
lcd[2+a+j][0+(a+3)*i] = '|';//??
}
}

public void digit_3(){
for (j=0 ; j<a ; j++){
lcd[0][1+j+(a+3)*i] = '-'; //?
lcd[2*a+2][1+j+(a+3)*i] = '-';//?
lcd[1+j][a+1+(a+3)*i] = '|';//??
lcd[a+1][1+j+(a+3)*i] = '-';//?
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}

public void digit_4(){
for (j=0 ; j<a ; j++){
lcd[1+j][0+(a+3)*i] = '|';//??
lcd[1+j][a+1+(a+3)*i] = '|';//??
lcd[a+1][1+j+(a+3)*i] = '-';//?
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}

public void digit_5(){
for (j=0 ; j<a ; j++){
lcd[0][1+j+(a+3)*i] = '-'; //?
lcd[2*a+2][1+j+(a+3)*i] = '-';//?
lcd[1+j][0+(a+3)*i] = '|';//??
lcd[a+1][1+j+(a+3)*i] = '-';//?
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}

public void digit_6(){
for (j=0 ; j<a ; j++){
lcd[0][1+j+(a+3)*i] = '-'; //?
lcd[2*a+2][1+j+(a+3)*i] = '-';//?
lcd[1+j][0+(a+3)*i] = '|';//??
lcd[a+1][1+j+(a+3)*i] = '-';//?
lcd[2+a+j][0+(a+3)*i] = '|';//??
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}

public void digit_7(){
for (j=0 ; j<a ; j++){
lcd[0][1+j+(a+3)*i] = '-'; //?
lcd[1+j][a+1+(a+3)*i] = '|';//??
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}

public void digit_8(){
for (j=0 ; j<a ; j++){
lcd[0][1+j+(a+3)*i] = '-'; //?
lcd[2*a+2][1+j+(a+3)*i] = '-';//?
lcd[1+j][0+(a+3)*i] = '|';//??
lcd[1+j][a+1+(a+3)*i] = '|';//??
lcd[a+1][1+j+(a+3)*i] = '-';//?
lcd[2+a+j][0+(a+3)*i] = '|';//??
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}

public void digit_9(){
for (j=0 ; j<a ; j++){
lcd[0][1+j+(a+3)*i] = '-'; //?
lcd[2*a+2][1+j+(a+3)*i] = '-';//?
lcd[1+j][0+(a+3)*i] = '|';//??
lcd[1+j][a+1+(a+3)*i] = '|';//??
lcd[a+1][1+j+(a+3)*i] = '-';//?
lcd[2+a+j][a+1+(a+3)*i] = '|';//??
}
}
// You can insert more classes here if you want.
}

//here is my coe
//but I got WA
//I don't know what wrong I hava
//please help me

Post Reply

Return to “Volume 7 (700-799)”