Page 1 of 15
706 - LCD Display
Posted: Tue Jun 25, 2002 8:42 am
by Sherman MXF
Can someone tell me where is wrong with my output?
[pascal]
program acm706;
type
coltype=array[1..30]of boolean;
const
t:array['0'..'9',1..3,1..3]of byte=(((1,1,0),(1,0,1),(1,1,0)),
((0,0,0),(0,0,0),(1,1,0)),
((0,1,0),(1,1,1),(1,0,0)),
((0,0,0),(1,1,1),(1,1,0)),
((1,0,0),(0,1,0),(1,1,0)),
((1,0,0),(1,1,1),(0,1,0)),
((1,1,0),(1,1,1),(0,1,0)),
((0,0,0),(1,0,0),(1,1,0)),
((1,1,0),(1,1,1),(1,1,0)),
((1,0,0),(1,1,1),(1,1,0)));
var
scr:array[1..30]of string;
size:byte;
s:string;
h:byte;
procedure readdata;
var
p:byte;
l:longint;
begin
readln(size,l);
str(l,s);
h:=size*2+3;
end;
procedure buildscreen;
var
l:byte;
col:coltype;
procedure convert(d:char;n:byte;var c:coltype);
var
i,j:byte;
begin
fillchar(c,sizeof(c),0);
case n of
1,3:begin
for i:=1 to 2 do
if t[d,n,i]=1 then
begin
for j:=(i-1)*(size+1)+2 to (i-1)*(size+1)+size+1 do
c[j]:=true;
end;
end;
2:begin
for i:=1 to 3 do
if t[d,n,i]=1 then c[(i-1)*(size+1)+1]:=true;
end;
end;
end;
procedure outcol(n:byte;c:coltype);
var
i,j:byte;
begin
case n of
1,3:begin
for i:=1 to h do
begin
if c then scr:=scr+'|' else scr:=scr+' ';
end;
end;
2:begin
for j:=1 to size do
begin
for i:=1 to h do
begin
if c then scr:=scr+'-' else scr:=scr+' ';
end;
end;
end;
end;
end;
procedure outdigit(d:char);
var
i:byte;
begin
for i:=1 to 3 do
begin
convert(d,i,col);
outcol(i,col);
end;
end;
begin
for l:=1 to 20 do
scr[l]:='';
for l:=1 to length(s) do
begin
outdigit(s[l]);
fillchar(col,sizeof(col),0);
outcol(1,col);
end;
end;
procedure out;
var
i:byte;
begin
for i:=1 to h do
begin
writeln(scr[i]);
end;
writeln;
end;
procedure run;
begin
repeat
readdata;
if size<>0 then
begin
buildscreen;
out;
end;
until size=0;
end;
begin
run;
end.
[/pascal]
Thanks.
Posted: Tue Jun 25, 2002 8:58 am
by xenon
The problem description says:
There has to be exactly one column of blanks between two digits.
Posted: Tue Jun 25, 2002 8:59 am
by Sherman MXF
Sorry, i found my array "scr" is too small...
help....
Posted: Sat Jul 06, 2002 12:02 pm
by Melon Melon
i get WA for this Qs..
i wonder what is the meaning of
Be sure to fill all the white space occupied by the digits with blanks, also for the last digit.
where the "last digit"... is it needed special manipulation on it??
i just treate it as usual digits..can i?????
Posted: Sat Jul 06, 2002 12:14 pm
by 10153EN
This is to fill all the white space occupied by the digits with blanks, also for the last digit:
[c]
bbbbbb--bbb--bbbbbbbb--b
bbb|bbbb|bbbb|b|bb|b|bbb
bbb|bbbb|bbbb|b|bb|b|bbb
bbbbbb--bbb--bbb--bbb--b
bbb|b|bbbbbbb|bbbb|bbbb|
bbb|b|bbbbbbb|bbbb|bbbb|
bbbbbb--bbb--bbbbbbbb--b
[/c]
This is to fill all the white space occupied by the digits with blanks, but not the last digit:
[c]
bbbbbb--bbb--bbbbbbbb--
bbb|bbbb|bbbb|b|bb|b|
bbb|bbbb|bbbb|b|bb|b|
bbbbbb--bbb--bbb--bbb--
bbb|b|bbbbbbb|bbbb|bbbb|
bbb|b|bbbbbbb|bbbb|bbbb|
bbbbbb--bbb--bbbbbbbb--
[/c]
where b is the blanks.
Hope can help~

Posted: Sat Jul 06, 2002 12:22 pm
by xenon
In the last digit also fill then 'unused space' at the end of the line with blanks:
Code: Select all
bbbn
bb|n
bbbn
bb|n
bbbn
b-bn
bb|n
b-bn
|bbn
b-bn
etc.
not:
n
bb|n
n
bb|n
n
b-n
bb|n
b-n
|n
b-n
here 'b' is a blank, 'n' is the end of line.
Posted: Sat Jul 06, 2002 12:26 pm
by xenon
10153EN:
We were writing replies simultaniously

Posted: Sat Jul 06, 2002 12:32 pm
by 10153EN
Haha... yes, and the idea of both messages are the same~

Posted: Sat Jul 06, 2002 1:23 pm
by Melon Melon
ths both..
...
i ve dealt with last digit..
but i dont know why still got WA....
...
here is my code...where get bugs???
[c]
#include <stdio.h>
#include <string.h>
/* global variables */
int no[10][7] = {{1, 1, 1, 0, 1, 1, 1},
{0, 0, 1, 0, 0, 1, 0},
{1, 0, 1, 1, 1 ,0, 1},
{1, 0, 1, 1, 0, 1, 1},
{0, 1, 1, 1, 0, 1, 0},
{1, 1, 0, 1, 0, 1, 1},
{1, 1, 0, 1, 1, 1, 1},
{1, 0, 1, 0, 0, 1, 0},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1}};
int len, s;
/* print "-" */
void row(char n[], int pos)
{
int j, k, digit;
for(j = 0; j < len; j++)
{
digit = n[j] - '0';
printf(" ");
if(no[digit][pos])
for(k = 0; k < s; k++)
printf("-");
else
for(k = 0; k < s; k++)
printf(" ");
printf(" ");
if(j != (len - 1))
printf(" ");
}
printf("\n");
}
/* print "|" */
void col(char n[], int pos1, int pos2)
{
int i, j, k, digit;
for(i = 0; i < s; i++)
{
for(j = 0; j < len; j++)
{
digit = n[j] - '0';
if(no[digit][pos1])
printf("|");
else
printf(" ");
for(k = 0; k < s; k++)
printf(" ");
if(no[digit][pos2])
printf("|");
else
printf(" ");
if(j != len - 1)
printf(" ");
}
printf("\n");
}
}
int main(int argv, char *argc[])
{
char n[100];
while(scanf("%d %s", &s, n) && s && (n[0] != '0'))
{
len = strlen(n);
row(n, 0);
col(n, 1, 2);
row(n, 3);
col(n, 4, 5);
row(n, 6);
putchar('\n');
}
return 0;
}
[/c]
Posted: Sat Jul 06, 2002 1:54 pm
by Picard
1 0
2 0
3 0
...
are all valid input pairs
Posted: Sat Jul 06, 2002 2:17 pm
by Melon Melon
oic...
ths a lot!!!
^___^
Posted: Tue Oct 08, 2002 10:39 pm
by doha200
[/cpp]
#include "iostream"
#include "string"
using namespace std;
bool A (char n)
{
if( n == '1' || n == '4')
return 0;
else
return 1;
}
bool B (char n)
{
if( n == '5' || n == '6')
return 0;
else
return 1;
}
bool C (char n)
{
if( n == '1' || n == '7' || n == '0')
return 0;
else
return 1;
}
bool D (char n)
{
if( n == '2')
return 0;
else
return 1;
}
bool E (char n)
{
if( n == '1' || n == '4' || n == '7')
return 0;
else
return 1;
}
bool F (char n)
{
if( n == '0' || n == '2' || n == '6' || n == '8')
return 1;
else
return 0;
}
bool G (char n)
{
if( n == '1' || n == '2' || n == '3' || n == '7')
return 0;
else
return 1;
}
void DisplayLCD (int size,string data)
{
int i,j,n;
int nRows,nCols;
nRows = 3 + 2*size;
nCols = 2 + size;
int h = -1;
bool RState = 0 , CState = 0;
for(i =0;i<nRows;i++)
{
for(n =0;n<data.size ();n++)
{
if(i%(nRows/2) == 0)
{
cout<<' ';
if(!i) h=i;
switch(h){
case 0:
RState = A(data[n]);
break;
case 1:
RState = C (data[n]);
break;
case 2:
RState = E (data[n]);
break;
}
for(j = 0;j<size;j++)
{
if(RState) cout<<'-';
else cout<<' ';
}
cout<<' ';
}
else
{
for(j =0;j<nCols;j++)
{
if(!h)
{
if(j == 0) CState = G (data[n]);
if(j == nCols-1) CState = B (data[n]);
}
else
{
if(j == 0) CState = F (data[n]);
if(j == nCols-1) CState = D (data[n]);
}
if(CState) cout<<'|';
else cout<<' ';
CState = 0;
}
}
cout<<'\t';
}
cout<<endl;
if(size != 1)
if(i%size == 0 && i > 0) h++;
if(size == 1)
if((i+1)%2 == 0) h++;
}
}
void main()
{
string data;
char line[80];
int size;
cin >> size;
while(size)
{
cin >> line;
data = line;
DisplayLCD (size,data);
cout<<endl;
cin >> size;
}
}
[/list]
706 WA
Posted: Mon Mar 17, 2003 5:36 pm
by evanmars
Seems to work for me. What case doesn't it work for?
// @JUDGE_ID: ******* 706 C++
#include <iostream.h>
#include <string.h>
int main()
{
int size, numlen;
char number[256];
char numerals[10][5][3] =
{{{' ','-',' '},{'|',' ','|'},
{' ',' ',' '},{'|',' ','|'},{' ','-',' '}},
{{' ',' ',' '},{' ',' ','|'},
{' ',' ',' '},{' ',' ','|'},{' ',' ',' '}},
{{' ','-',' '},{' ',' ','|'},
{' ','-',' '},{'|',' ',' '},{' ','-',' '}},
{{' ','-',' '},{' ',' ','|'},
{' ','-',' '},{' ',' ','|'},{' ','-',' '}},
{{' ',' ',' '},{'|',' ','|'},
{' ','-',' '},{' ',' ','|'},{' ',' ',' '}},
{{' ','-',' '},{'|',' ',' '},
{' ','-',' '},{' ',' ','|'},{' ','-',' '}},
{{' ','-',' '},{'|',' ',' '},
{' ','-',' '},{'|',' ','|'},{' ','-',' '}},
{{' ','-',' '},{' ',' ','|'},
{' ',' ',' '},{' ',' ','|'},{' ',' ',' '}},
{{' ','-',' '},{'|',' ','|'},
{' ','-',' '},{'|',' ','|'},{' ','-',' '}},
{{' ','-',' '},{'|',' ','|'},
{' ','-',' '},{' ',' ','|'},{' ',' ',' '}}};
while(1)
{
cin >> size >> number;
numlen = strlen(number);
if(size == 0 && strchr(number,'0') != NULL)
break;
if(size != 0)
{
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < numlen; j++)
{
cout << numerals[number[j]-48][0];
for(int k = 0; k < size; k++)
cout << numerals[number[j]-48][1];
cout << numerals[number[j]-48][2];
cout<< ' ';
}
cout << endl;
if(i%2)
{
for(int l = 0; l < size - 1; l++)
{
for(int m = 0; m < numlen; m++)
{
cout << numerals[number[m]-48][0];
for(int n = 0; n < size; n++)
cout << numerals[number[m]-48][1];
cout << numerals[number[m]-48][2];
cout << ' ';
}
cout << endl;
}
}
}
}
}
return 0;
}
706 LCD - WA
Posted: Wed Mar 19, 2003 10:41 pm
by Pasq
Can you help me, why I got WA ?
[pascal]
program dupa;
var
wie :longint;
jakie :string;
i,j :longint;
n :longint;
puste,pelne :string;
begin
readln(wie,jakie);
while wie>0 do
begin
pelne:='';
puste:='';
n:=length(jakie);
for i:=1 to wie do
begin
puste:=puste+' ';
pelne:=pelne+'-';
end;
for i:=2 to n do
begin
write(' ');
case jakie of
'1':write(puste);
'4':write(puste);
else write(pelne);
end;
write(' ');
if i<>n then write(' ');
end;
writeln;
for j:=1 to wie do
begin
for i:=2 to n do
begin
case jakie of
'4':write('|');
'5':write('|');
'6':write('|');
'8':write('|');
'9':write('|');
'0':write('|');
else write(' ');
end;
write(puste);
case jakie of
'1':write('|');
'2':write('|');
'3':write('|');
'4':write('|');
'7':write('|');
'8':write('|');
'9':write('|');
'0':write('|');
else write(' ');
end;
if i<>n then write(' ');
end;
writeln;
end;
for i:=2 to n do
begin
write(' ');
case jakie of
'1':write(puste);
'7':write(puste);
'0':write(puste);
else write(pelne);
end;
write(' ');
if i<>n then write(' ');
end;
writeln;
for j:=1 to wie do
begin
for i:=2 to n do
begin
case jakie of
'2':write('|');
'6':write('|');
'8':write('|');
'0':write('|');
else write(' ');
end;
write(puste);
case jakie of
'1':write('|');
'3':write('|');
'4':write('|');
'5':write('|');
'6':write('|');
'7':write('|');
'8':write('|');
'9':write('|');
'0':write('|');
else write(' ');
end;
if i<>n then write(' ');
end;
writeln;
end;
for i:=2 to n do
begin
write(' ');
case jakie of
'1':write(puste);
'4':write(puste);
'7':write(puste);
else write(pelne);
end;
write(' ');
if i<>n then write(' ');
end;
writeln;
readln(wie,jakie);
if wie<>0
then
writeln;
end;
end.
[/pascal]
or give me an example where my program gives WA.
Posted: Sat Apr 12, 2003 2:14 pm
by Eric
Would you use the [C++][/C++] code to format your program well in order to let other people read your program more easily?
Otherwise, other people can hardly help you.