706 - LCD Display
Moderator: Board moderators
-
- New poster
- Posts: 10
- Joined: Mon Mar 28, 2005 5:59 pm
- Location: Dhaka, Bangladesh
- Contact:
Thanks Raiyan Kamal, that was now accepted.
Yes, i changed my code to handle leading zero printing. and got accepted (PE) result from the judge. I'll correct the PE later. But any way thanks.
Programmer? No, no, i am a speedy typist.
706 Rejected for wrong answer
I want to join the cool club of solving the LCD problem 706. Here is my code and a few examples. For the post, I have left "."'s instead of what I would send in with " "'s. Here is the code. It's in C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define RWIDTH (2*size+3)
void printh(int, int);
void printv(int, int, int);
int main(){
char buffer[80];
char numlist[9], ch[2];
/*map[] contains binary number with 1 in each spot
for top, top-left, top-right, middle,bottom-left,
bottom-right, bottom. map[8] = 011111111 (each number
takes up a byte leading 0 means nothing.*/
int map[10] = {119,18,93,91,58,107,111,82,127,123};
int size, rnum;
int i, row, inNum, left, right;
while(1){/*Loop forever unless broken*/
/*Get numbers and appropriate them. End if 0 0 is entered.*/
fgets(buffer, 80, stdin);
sscanf(buffer, "%d %s", &size, &numlist);
rnum = atoi(numlist);
if(size == 0 && rnum == 0){break;}
/*Cycle through rows*/
for(row = 1;row <= RWIDTH;row++){
/*Cycle through each number*/
for(i=0;i<strlen(numlist);i++){
ch[0] = numlist;
ch[1] = '\0';
inNum = atoi(ch);
/*Print Horizontal bars*/
if((((map[inNum] & 64) == 64) && row==1) ||
(((map[inNum] & 8) == 8 ) && row == (RWIDTH/2+1)) ||
(((map[inNum] & 1) == 1 ) && row == RWIDTH)){
printh(1,size);
}
else
if(row == 1 || row == (RWIDTH/2+1) || row == RWIDTH){
printh(0,size);
}
/*Print Vertical bars*/
if(row > 1 && row < (RWIDTH/2+1)){
if((map[inNum] & 32)==32){left = 1;}
else{left=0;}
if((map[inNum] & 16)==16){right = 1;}
else{right=0;}
printv(size, left, right);
}
if((row > (RWIDTH/2+1)) && (row < RWIDTH)){
if((map[inNum] & 4)==4){left = 1;}
else{left=0;}
if((map[inNum] & 2)==2){right = 1;}
else{right=0;}
printv(size, left, right);
}
if(strlen(numlist)-1 != i){printf(".");}
}/*Close number cycling*/
printf("\n");
}/*Close row cycling*/
}/*Close while Loop*/
return 0;
}/*Close main()*/
/*Print Horizontal lines for top, middle or bottem rows*/
void printh(int yes, int size){
int h;
printf(".");
if(yes){
for(h=0;h<size;h++){printf("-");}
}else{
for(h=0;h<size;h++){printf(".");}
}
printf(".");
}
/*Print Vertical Left lines, print middle spaces and Right lines*/
void printv(int size, int l, int r){
int v;
if(l){printf("|");}
else{printf(".");}
for(v=0;v<size;v++){printf(".");}
if(r){printf("|");}
else{printf(".");}
}
Examples:
2 01235
4 99999
0 0
.--........--...--...--.
|..|....|....|....|.|...
|..|....|....|....|.|...
...........--...--...--.
|..|....|.|.......|....|
|..|....|.|.......|....|
.--........--...--...--.
.----...----...----...----...----.
|....|.|....|.|....|.|....|.|....|
|....|.|....|.|....|.|....|.|....|
|....|.|....|.|....|.|....|.|....|
|....|.|....|.|....|.|....|.|....|
.----...----...----...----...----.
.....|......|......|......|......|
.....|......|......|......|......|
.....|......|......|......|......|
.....|......|......|......|......|
.----...----...----...----...----.
I just got this accepted. I needed to add '\n' after each entries output except the last one.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define RWIDTH (2*size+3)
void printh(int, int);
void printv(int, int, int);
int main(){
char buffer[80];
char numlist[9], ch[2];
/*map[] contains binary number with 1 in each spot
for top, top-left, top-right, middle,bottom-left,
bottom-right, bottom. map[8] = 011111111 (each number
takes up a byte leading 0 means nothing.*/
int map[10] = {119,18,93,91,58,107,111,82,127,123};
int size, rnum;
int i, row, inNum, left, right;
while(1){/*Loop forever unless broken*/
/*Get numbers and appropriate them. End if 0 0 is entered.*/
fgets(buffer, 80, stdin);
sscanf(buffer, "%d %s", &size, &numlist);
rnum = atoi(numlist);
if(size == 0 && rnum == 0){break;}
/*Cycle through rows*/
for(row = 1;row <= RWIDTH;row++){
/*Cycle through each number*/
for(i=0;i<strlen(numlist);i++){
ch[0] = numlist;
ch[1] = '\0';
inNum = atoi(ch);
/*Print Horizontal bars*/
if((((map[inNum] & 64) == 64) && row==1) ||
(((map[inNum] & 8) == 8 ) && row == (RWIDTH/2+1)) ||
(((map[inNum] & 1) == 1 ) && row == RWIDTH)){
printh(1,size);
}
else
if(row == 1 || row == (RWIDTH/2+1) || row == RWIDTH){
printh(0,size);
}
/*Print Vertical bars*/
if(row > 1 && row < (RWIDTH/2+1)){
if((map[inNum] & 32)==32){left = 1;}
else{left=0;}
if((map[inNum] & 16)==16){right = 1;}
else{right=0;}
printv(size, left, right);
}
if((row > (RWIDTH/2+1)) && (row < RWIDTH)){
if((map[inNum] & 4)==4){left = 1;}
else{left=0;}
if((map[inNum] & 2)==2){right = 1;}
else{right=0;}
printv(size, left, right);
}
if(strlen(numlist)-1 != i){printf(".");}
}/*Close number cycling*/
printf("\n");
}/*Close row cycling*/
}/*Close while Loop*/
return 0;
}/*Close main()*/
/*Print Horizontal lines for top, middle or bottem rows*/
void printh(int yes, int size){
int h;
printf(".");
if(yes){
for(h=0;h<size;h++){printf("-");}
}else{
for(h=0;h<size;h++){printf(".");}
}
printf(".");
}
/*Print Vertical Left lines, print middle spaces and Right lines*/
void printv(int size, int l, int r){
int v;
if(l){printf("|");}
else{printf(".");}
for(v=0;v<size;v++){printf(".");}
if(r){printf("|");}
else{printf(".");}
}
Examples:
2 01235
4 99999
0 0
.--........--...--...--.
|..|....|....|....|.|...
|..|....|....|....|.|...
...........--...--...--.
|..|....|.|.......|....|
|..|....|.|.......|....|
.--........--...--...--.
.----...----...----...----...----.
|....|.|....|.|....|.|....|.|....|
|....|.|....|.|....|.|....|.|....|
|....|.|....|.|....|.|....|.|....|
|....|.|....|.|....|.|....|.|....|
.----...----...----...----...----.
.....|......|......|......|......|
.....|......|......|......|......|
.....|......|......|......|......|
.....|......|......|......|......|
.----...----...----...----...----.
I just got this accepted. I needed to add '\n' after each entries output except the last one.
-
- New poster
- Posts: 23
- Joined: Sat Oct 04, 2003 12:12 pm
- Location: in Your Heart ^^
- Contact:
thanx a lot for the hints kiha, i was wondering why i got a RTE SIGSEGV, now i know that i didnt handle other input which was not '0' - '9'kiha wrote: ...
...
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
...
...
Good luck to you solvers
Every person exists for another person. and that person exists for the other one. it's just the matter of existence...
May every person helps each other and creates a world full of joy...
May every person helps each other and creates a world full of joy...
706 Wrong answers....
I have tried most of the test cases, but still resulted in "Wrong answer". Can anyone tell me wt'z wrong or give me some critical test cases???
Thank you...
Code: Select all
var
sto:array[1..1000000] of string;
pe:array[1..1000000] of integer;
inp:string;
p,i,j,m,a,n:longint;
ans:array[1..100000] of string;
procedure one(s:integer);
var
x,y:integer;
begin
for x:=1 to s+2 do
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
for x:=1 to s+2 do
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+2+s do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
for x:=1 to s+2 do
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure two(s:integer);
var
x,y:integer;
begin
ans[1]:=concat(ans[1], ' ');
for x:=1 to s do
ans[1]:=concat(ans[1], '-');
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+2]:=concat(ans[s+2], ' ');
for x:=1 to s do
ans[s+2]:=concat(ans[s+2], '-');
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+s+2 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
end;
ans[s+s+3]:=concat(ans[s+s+3], ' ');
for x:=1 to s do
ans[s+s+3]:=concat(ans[s+s+3], '-');
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure three(s:integer);
var
x,y:integer;
begin
ans[1]:=concat(ans[1], ' ');
for x:=1 to s do
ans[1]:=concat(ans[1], '-');
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+2]:=concat(ans[s+2], ' ');
for x:=1 to s do
ans[s+2]:=concat(ans[s+2], '-');
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+s+2 do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+s+3]:=concat(ans[s+s+3], ' ');
for x:=1 to s do
ans[s+s+3]:=concat(ans[s+s+3], '-');
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure four(s:integer);
var
x,y:integer;
begin
for x:=1 to s+2 do
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+2]:=concat(ans[s+2], ' ');
for x:=1 to s do
ans[s+2]:=concat(ans[s+2], '-');
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+s+2 do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
for x:=1 to s+2 do
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure five(s:integer);
var
x,y:integer;
begin
ans[1]:=concat(ans[1], ' ');
for x:=1 to s do
ans[1]:=concat(ans[1], '-');
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
end;
ans[s+2]:=concat(ans[s+2], ' ');
for x:=1 to s do
ans[s+2]:=concat(ans[s+2], '-');
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+s+2 do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+s+3]:=concat(ans[s+s+3], ' ');
for x:=1 to s do
ans[s+s+3]:=concat(ans[s+s+3], '-');
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure six(s:integer);
var
x,y:integer;
begin
ans[1]:=concat(ans[1], ' ');
for x:=1 to s do
ans[1]:=concat(ans[1], '-');
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
end;
ans[s+2]:=concat(ans[s+2], ' ');
for x:=1 to s do
ans[s+2]:=concat(ans[s+2], '-');
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+s+2 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+s+3]:=concat(ans[s+s+3], ' ');
for x:=1 to s do
ans[s+s+3]:=concat(ans[s+s+3], '-');
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure seven(s:integer);
var
x,y:integer;
begin
ans[1]:=concat(ans[1], ' ');
for x:=1 to s do
ans[1]:=concat(ans[1], '-');
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
for x:=1 to s+2 do
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+2+s do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
for x:=1 to s+2 do
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure eight(s:integer);
var
x,y:integer;
begin
ans[1]:=concat(ans[1], ' ');
for x:=1 to s do
ans[1]:=concat(ans[1], '-');
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+2]:=concat(ans[s+2], ' ');
for x:=1 to s do
ans[s+2]:=concat(ans[s+2], '-');
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+s+2 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+s+3]:=concat(ans[s+s+3], ' ');
for x:=1 to s do
ans[s+s+3]:=concat(ans[s+s+3], '-');
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure nine(s:integer);
var
x,y:integer;
begin
ans[1]:=concat(ans[1], ' ');
for x:=1 to s do
ans[1]:=concat(ans[1], '-');
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+2]:=concat(ans[s+2], ' ');
for x:=1 to s do
ans[s+2]:=concat(ans[s+2], '-');
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+s+2 do
begin
for y:=1 to s+1 do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+s+3]:=concat(ans[s+s+3], ' ');
for x:=1 to s do
ans[s+s+3]:=concat(ans[s+s+3], '-');
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
procedure zero(s:integer);
var
x,y:integer;
begin
ans[1]:=concat(ans[1], ' ');
for x:=1 to s do
ans[1]:=concat(ans[1], '-');
ans[1]:=concat(ans[1], ' ');
for x:=2 to s+1 do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
for x:=1 to s+2 do
ans[s+2]:=concat(ans[s+2], ' ');
for x:=s+3 to s+2+s do
begin
ans[x]:=concat(ans[x], '|');
for y:=1 to s do
ans[x]:=concat(ans[x], ' ');
ans[x]:=concat(ans[x], '|');
end;
ans[s+s+3]:=concat(ans[s+s+3], ' ');
for x:=1 to s do
ans[s+s+3]:=concat(ans[s+s+3], '-');
ans[s+s+3]:=concat(ans[s+s+3], ' ');
end;
begin
a:=1;
p:=1;
inp:='2';
repeat
readln(p, inp);
delete(inp, 1,1);
sto[a]:=inp;
pe[a]:=p;
a:=a+1;
until (p=0) and (inp='0');
for n:=1 to a-2 do
begin
for i:=1 to 2*pe[n]+3 do
ans[i]:='';
for i:=1 to length(sto[n]) do
begin
if sto[n][i]='1' then one(pe[n]);
if sto[n][i]='2' then two(pe[n]);
if sto[n][i]='3' then three(pe[n]);
if sto[n][i]='4' then four(pe[n]);
if sto[n][i]='5' then five(pe[n]);
if sto[n][i]='6' then six(pe[n]);
if sto[n][i]='7' then seven(pe[n]);
if sto[n][i]='8' then eight(pe[n]);
if sto[n][i]='9' then nine(pe[n]);
if sto[n][i]='0' then zero(pe[n]);
for j:=1 to 2*pe[n]+3 do
if i<>length(sto[n]) then ans[j]:=concat(ans[j], ' ');
end;
for i:=1 to 2*pe[n]+3 do
begin
writeln(ans[i]);
end;
writeln;
end;
readln
end.
-
- New poster
- Posts: 9
- Joined: Sat Oct 18, 2003 2:08 pm
706 WA >.<
I got WA can't i can't solve it, anyone can help? Thanks~
Code: Select all
#include<iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
int s;
string str_n;
int ptr_n;
cin>>s>>str_n;
while(s)
{
ptr_n=0;
int i;
for(i=0;i<2*s+3;i++)
{
while(str_n[ptr_n])
{
if(ptr_n)
cout<<" ";
if(i==0)
{
switch(str_n[ptr_n]) //first line
{
case '1':
case '4':
cout<<setw(s+2)<<" ";
break;
case '2':
case '3':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
cout<<" "<<setfill('-')<<setw(s+1)<<" "<<setfill(' ');
break;
}
}
else if(i<s+1) //upper half
{
switch(str_n[ptr_n])
{
case '1':
case '2':
case '3':
case '7':
cout<<setw(s+2)<<"|";
break;
case '4':
case '8':
case '9':
case '0':
cout<<"|"<<setw(s+1)<<"|";
break;
case '5':
case '6':
cout<<"|"<<setw(s+1)<<" ";
break;
}
}
else if(i==s+1) //middle line
{
switch(str_n[ptr_n])
{
case '1':
case '7':
case '0':
cout<<setw(s+2)<<" ";
break;
case '2':
case '3':
case '4':
case '5':
case '6':
case '8':
case '9':
cout<<" "<<setfill('-')<<setw(s+1)<<" "<<setfill(' ');
break;
}
}
else if(i<2*s+2) //lower half
{
switch(str_n[ptr_n])
{
case '1':
case '3':
case '4':
case '5':
case '7':
case '9':
cout<<setw(s+2)<<"|";
break;
case '2':
cout<<"|"<<setw(s+1)<<" ";
break;
case '6':
case '8':
case '0':
cout<<"|"<<setw(s+1)<<"|";
break;
}
}
else //if(i==2*s+2) //last line
{
switch(str_n[ptr_n])
{
case '1':
case '4':
case '7':
cout<<setw(s+2)<<" ";
break;
case '2':
case '3':
case '5':
case '6':
case '8':
case '9':
case '0':
cout<<" "<<setfill('-')<<setw(s+1)<<" "<<setfill(' ');
break;
}
}
ptr_n++;
}
cout<<endl;
ptr_n=0;
}
cin>>s>>str_n;
if(s)
cout<<endl;
}
return 0;
}
706

i am surprisesd with ur procedures function. Cann't u declare a three dimension array? Declare a 3 dimen array of 10 digit and display it with procedures.
roni(SUST)
-
- New poster
- Posts: 2
- Joined: Tue Jan 24, 2006 2:39 am
706 - Java WA
Again, I don't know what I'm doing wrong (probably the same things that I'm doing wrong in all my other submissions ><) but I hope somebody can help me clear up why I keep getting a WA on this code.
Here is the source and a test case:
Here is the source and a test case:
Code: Select all
import java.io.*;
class Main
{
String[] One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Zero;
String Begin(String Input, int Dimension)
{
Input = Input.substring(Input.indexOf(' ')+1, Input.length());
if (Input.indexOf('1') != -1)
{
One = new String[5];
One[0] = " ";
One[1] = " |";
One[2] = " ";
One[3] = " |";
One[4] = " ";
One = Stretch(One, Dimension);
}
if (Input.indexOf('2') != -1)
{
Two = new String[5];
Two[0] = " - ";
Two[1] = " |";
Two[2] = " - ";
Two[3] = "| ";
Two[4] = " - ";
Two = Stretch(Two, Dimension);
}
if (Input.indexOf('3') != -1)
{
Three = new String[5];
Three[0] = " - ";
Three[1] = " |";
Three[2] = " - ";
Three[3] = " |";
Three[4] = " - ";
Three = Stretch(Three, Dimension);
}
if (Input.indexOf('4') != -1)
{
Four = new String[5];
Four[0] = " ";
Four[1] = "| |";
Four[2] = " - ";
Four[3] = " |";
Four[4] = " ";
Four = Stretch(Four, Dimension);
}
if (Input.indexOf('5') != -1)
{
Five = new String[5];
Five[0] = " - ";
Five[1] = "| ";
Five[2] = " - ";
Five[3] = " |";
Five[4] = " - ";
Five = Stretch(Five, Dimension);
}
if (Input.indexOf('6') != -1)
{
Six = new String[5];
Six[0] = " - ";
Six[1] = "| ";
Six[2] = " - ";
Six[3] = "| |";
Six[4] = " - ";
Six = Stretch(Six, Dimension);
}
if (Input.indexOf('7') != -1)
{
Seven = new String[5];
Seven[0] = " - ";
Seven[1] = " |";
Seven[2] = " ";
Seven[3] = " |";
Seven[4] = " ";
Seven = Stretch(Seven, Dimension);
}
if (Input.indexOf('8') != -1)
{
Eight = new String[5];
Eight[0] = " - ";
Eight[1] = "| |";
Eight[2] = " - ";
Eight[3] = "| |";
Eight[4] = " - ";
Eight = Stretch(Eight, Dimension);
}
if (Input.indexOf('9') != -1)
{
Nine = new String[5];
Nine[0] = " - ";
Nine[1] = "| |";
Nine[2] = " - ";
Nine[3] = " |";
Nine[4] = " - ";
Nine = Stretch(Nine, Dimension);
}
if (Input.indexOf('0') != -1)
{
Zero = new String[5];
Zero[0] = " - ";
Zero[1] = "| |";
Zero[2] = " ";
Zero[3] = "| |";
Zero[4] = " - ";
Zero = Stretch(Zero, Dimension);
}
String[] Answer = new String[2*Dimension+3];
for (int i = 0; i < Answer.length; i++)
Answer[i] = "";
for (int i = 0; i < Input.length(); i++)
{
switch (Input.charAt(i))
{
case '1':
for (int j = 0; j < Answer.length; j++)
Answer[j] += One[j] + " ";
break;
case '2':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Two[j] + " ";
break;
case '3':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Three[j] + " ";
break;
case '4':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Four[j] + " ";
break;
case '5':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Five[j] + " ";
break;
case '6':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Six[j] + " ";
break;
case '7':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Seven[j] + " ";
break;
case '8':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Eight[j] + " ";
break;
case '9':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Nine[j] + " ";
break;
case '0':
for (int j = 0; j < Answer.length; j++)
Answer[j] += Zero[j] + " ";
break;
}
}
return ToString(Answer);
}
void Begin()
{
String Answer = "";
String Input = ReadLine(255);
while (!Input.equals("0 0"))
{
int Dimension = Integer.parseInt(Input.substring(0, Input.indexOf(' ')));
if (Dimension != 0)
{
Answer += Begin(Input, Dimension);
}
Input = ReadLine(255);
}
System.out.println(Answer);
}
static void main(String[] args)
{
Main LCD = new Main();
LCD.Begin();
}
static String ReadLine (int maxLg) {
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try {
while (lg < maxLg) {
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e) { return (null); }
if ((car < 0) && (lg == 0)) return (null);
return (new String (lin, 0, lg));
}
String[] Stretch(String[] Input, int Dimension)
{
Dimension--;
//Widen
for (int i = 0; i < Input.length; i++)
{
for (int j = 0; j < Dimension; j++)
{
Input[i] = Input[i].substring(0,2) + Input[i].substring(1,Input[i].length());
}
}
//Heighten
for (int i = 0; i < Dimension; i++)
{
String[] NewInput = new String[Input.length+2];
NewInput[0] = Input[0];
NewInput[1] = Input[1];
for (int j = 2; j < NewInput.length-2; j++)
NewInput[j] = Input[j-1];
NewInput[NewInput.length-2] = Input[Input.length-2];
NewInput[NewInput.length-1] = Input[Input.length-1];
Input = NewInput;
}
return Input;
}
void Output(String[] Input)
{
for (int i = 0; i < Input.length; i++)
{
System.out.println(Input[i].substring(0, Input[i].length()-1));
}
System.out.println();
}
String ToString(String[] Input)
{
String Answer = "";
for (int i = 0; i < Input.length; i++)
{
Answer += Input[i].substring(0, Input[i].length()-1) + "\n";
}
return Answer + "\n";
}
}
Code: Select all
1 1092387456
2 1234567890
3 0987654321
4 83
5 009584731
6 2247
0 0
- - - - - - - -
| | | | | | | | | | | | | |
- - - - - - -
| | | | | | | | | | | | |
- - - - - - -
-- -- -- -- -- -- -- --
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
-- -- -- -- -- -- --
| | | | | | | | | | | | |
| | | | | | | | | | | | |
-- -- -- -- -- -- --
--- --- --- --- --- --- --- ---
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
--- --- --- --- --- --- ---
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
--- --- --- --- --- --- ---
---- ----
| | |
| | |
| | |
| | |
---- ----
| | |
| | |
| | |
| | |
---- ----
----- ----- ----- ----- ----- ----- -----
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
----- ----- ----- ----- -----
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
----- ----- ----- ----- ----- -----
------ ------ ------
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
------ ------ ------
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
------ ------
-
- New poster
- Posts: 21
- Joined: Tue Jan 10, 2006 12:25 am
706 LCD Display WA + My Samples
here are my I/O for diff cases Please can anyone help me to detect what is wrong ?
Code: Select all
...................... .--------------------. .--------------------. ...................... ......................
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
.....................| .....................| .....................| .....................| |....................|
...................... .--------------------. .--------------------. ...................... .--------------------.
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
.....................| |..................... .....................| .....................| .....................|
...................... .--------------------. .--------------------. ...................... ......................
.................................................... .--------------------------------------------------. .................................................... .--------------------------------------------------. .--------------------------------------------------. .--------------------------------------------------. .--------------------------------------------------.
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
...................................................| ...................................................| |..................................................| |..................................................| |................................................... |..................................................| |..................................................|
.................................................... .--------------------------------------------------. .--------------------------------------------------. .--------------------------------------------------. .--------------------------------------------------. .--------------------------------------------------. ....................................................
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
...................................................| ...................................................| ...................................................| ...................................................| ...................................................| ...................................................| |..................................................|
.................................................... .--------------------------------------------------. .................................................... .--------------------------------------------------. .--------------------------------------------------. .--------------------------------------------------. .--------------------------------------------------.
-
- New poster
- Posts: 21
- Joined: Tue Jan 10, 2006 12:25 am
706.. Why WA ?
#include <stdio.h>
#include <string.h>
void main()
{
int s, i, j, k, l, row, col, idx;
char n[10];
do {
scanf("%d", &s);
scanf("%s", &n);
if(s==0) break;
col= s+2;
row= 2*s+3;
l= strlen(n);
if(n[0]!='0') for(idx=0;n[idx]=='0'&&idx<l;idx++);
else idx= l-1;
for(j=1;j<=row;j++) {
for(k=idx;k<l;k++) {
for(i=1;i<=col;i++) {
if(j==1) {
if( n[k]!='1'&&n[k]!='4' && !(i==1||i==col) )
putchar('-');
else
putchar(' ');
}
else
if(j==row) {
if( n[k]!='1'&&n[k]!='4'&&n[k]!='7' && !(i==1||i==col) )
putchar('-');
else
putchar(' ');
}
else
if(j<(row+1)/2) {
if( n[k]!='5'&&n[k]!='6' && i==col )
putchar('|');
else
if( n[k]!='1'&&n[k]!='2'&&n[k]!='3'&&n[k]!='7' && i==1 )
putchar('|');
else
putchar(' ');
}
else
if(j==(row+1)/2) {
if( n[k]!='1'&&n[k]!='7'&&n[k]!='0' && !(i==1||i==col) )
putchar('-');
else
putchar(' ');
}
else
if(j>(col+1)/2) {
if( n[k]!='2' && i==col )
putchar('|');
else
if( (n[k]=='2'||n[k]=='6'||n[k]=='8'||n[k]=='0') && i==1 )
putchar('|');
else
putchar(' ');
}
}
putchar(' ');
}
puts("");
}
} while(1);
}
//Can Someone help me to fix this problem? Thx..

#include <string.h>
void main()
{
int s, i, j, k, l, row, col, idx;
char n[10];
do {
scanf("%d", &s);
scanf("%s", &n);
if(s==0) break;
col= s+2;
row= 2*s+3;
l= strlen(n);
if(n[0]!='0') for(idx=0;n[idx]=='0'&&idx<l;idx++);
else idx= l-1;
for(j=1;j<=row;j++) {
for(k=idx;k<l;k++) {
for(i=1;i<=col;i++) {
if(j==1) {
if( n[k]!='1'&&n[k]!='4' && !(i==1||i==col) )
putchar('-');
else
putchar(' ');
}
else
if(j==row) {
if( n[k]!='1'&&n[k]!='4'&&n[k]!='7' && !(i==1||i==col) )
putchar('-');
else
putchar(' ');
}
else
if(j<(row+1)/2) {
if( n[k]!='5'&&n[k]!='6' && i==col )
putchar('|');
else
if( n[k]!='1'&&n[k]!='2'&&n[k]!='3'&&n[k]!='7' && i==1 )
putchar('|');
else
putchar(' ');
}
else
if(j==(row+1)/2) {
if( n[k]!='1'&&n[k]!='7'&&n[k]!='0' && !(i==1||i==col) )
putchar('-');
else
putchar(' ');
}
else
if(j>(col+1)/2) {
if( n[k]!='2' && i==col )
putchar('|');
else
if( (n[k]=='2'||n[k]=='6'||n[k]=='8'||n[k]=='0') && i==1 )
putchar('|');
else
putchar(' ');
}
}
putchar(' ');
}
puts("");
}
} while(1);
}
//Can Someone help me to fix this problem? Thx..


2 blank lines in the end!
Hello! I had a few (actually a LOT OF) problems with this problem and I only could get AC when I made my program print 2 blank lines ate the end of the output file!
Another hint: be carefull about printing a blank column after the last LCD-digit in a line.
Hope it helps!
See ya!
Another hint: be carefull about printing a blank column after the last LCD-digit in a line.
Hope it helps!
See ya!
"Don't let the day go by
Don't let it end
Don't let the day go by, in doubts
The anwser lis within"
Don't let it end
Don't let the day go by, in doubts
The anwser lis within"
706 - LC-Display - WA
Hi.
I've got WA in this problem.
I've read the articles discussed about this problem but still didn't
figure out how to correct.
Online Judge still show WA after I fixed some place every time.
Can any one help me look about where my wrong is ?
Thanks.
I've got WA in this problem.

I've read the articles discussed about this problem but still didn't
figure out how to correct.
Online Judge still show WA after I fixed some place every time.
Can any one help me look about where my wrong is ?
Thanks.

Code: Select all
#include <stdio.h>
void draw(int mode, int size){
int i = 1;
for(i = 1; i<= size ; i++){
if(mode == 1)putchar('-');
else if(mode == 2) putchar('|');
else putchar(' ');
}
}
int main(){
int size, number, i, j, k, digit[8] = {0}, length, time = 0;
while(scanf("%d %d", &size, &number) == 2 && !(size == 0 && number == 0)) {
length = 0;
/*if(time != 0) putchar('\n');
time = 1; */
for(i = 0 ; number > 0 ; i++ ){
digit[i] = number % 10;
number /= 10 ;
length++;
}
if(number == 0) {
length = 1;
digit[0] = 0;
}
/**********TOP******/
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 4:
{
putchar(' ');
draw(3,size);
putchar(' ');
break;
}
default:{
putchar(' ');
draw(1,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
/********UP********/
for(j = 1 ; j <= size ; j++){
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 2:
case 3:
case 7:
{
putchar(' ');
draw(3,size);
putchar('|');
break;
}
case 4:
case 8:
case 9:
case 0:
{
putchar('|');
draw(3,size);
putchar('|');
break;
}
default:
{
putchar('|');
draw(3,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
}
/***********MIDDLE*****/
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 0:
case 7:
{
putchar(' ');
draw(3,size);
putchar(' ');
break;
}
default:{
putchar(' ');
draw(1,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
/******DOWN**********/
for(j = 1 ; j <= size ; j++){
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 4:
case 3:
case 5:
case 7:
case 9:
{
putchar(' ');
draw(3,size);
putchar('|');
break;
}
case 6:
case 8:
case 0:
{
putchar('|');
draw(3,size);
putchar('|');
break;
}
default:
{
putchar('|');
draw(3,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
}
/*****FLOOR***********/
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 4:
case 7:
{
putchar(' ');
draw(3,size);
putchar(' ');
break;
}
default:{
putchar(' ');
draw(1,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
/****************/
putchar('\n');
}
return 0;
}
Sorry.
I've found where my wrong is.
At first, I want to fix a situation when the input is : X 0
( X means some number as size , such as input is 5 0)
But I did't handle it very well. And comes out the code I posted before.
Now, I've fixed it and got AC.
Here, I List my Code.
Finally, Here's some opinions about this problem, and maybe they can help somebody else who got WA.
1. Space or NewLine that have mentioned in previous Post.
2. Maybe the code will meet some problem in some input sets such as
input is X 0
3. I didn't handle the leading 0 situation,
that means if input is 00007, my out put is 7.
Thanks
I've found where my wrong is.
At first, I want to fix a situation when the input is : X 0
( X means some number as size , such as input is 5 0)
But I did't handle it very well. And comes out the code I posted before.
Now, I've fixed it and got AC.
Here, I List my Code.
Finally, Here's some opinions about this problem, and maybe they can help somebody else who got WA.
1. Space or NewLine that have mentioned in previous Post.
2. Maybe the code will meet some problem in some input sets such as
input is X 0
3. I didn't handle the leading 0 situation,
that means if input is 00007, my out put is 7.
Thanks

Code: Select all
#include <stdio.h>
void draw(int mode, int size){
int i = 1;
for(i = 1; i<= size ; i++){
if(mode == 1)putchar('-');
else if(mode == 2) putchar('|');
else putchar(' ');
}
}
int main(){
int size, number, i, j, k, digit[8] = {0}, length, time = 0;
while(scanf("%d %d", &size, &number) == 2 && !(size == 0 && number == 0)) {
length = 0;
/*if(time != 0) putchar('\n');
time = 1; */
if(number == 0) {
length = 1;
digit[0] = 0;
}
/***FIX****/
else{
for(i = 0 ; number > 0 ; i++ ){
digit[i] = number % 10;
number /= 10 ;
length++;
}
}
/**********TOP******/
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 4:
{
putchar(' ');
draw(3,size);
putchar(' ');
break;
}
default:{
putchar(' ');
draw(1,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
/********UP********/
for(j = 1 ; j <= size ; j++){
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 2:
case 3:
case 7:
{
putchar(' ');
draw(3,size);
putchar('|');
break;
}
case 4:
case 8:
case 9:
case 0:
{
putchar('|');
draw(3,size);
putchar('|');
break;
}
default:
{
putchar('|');
draw(3,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
}
/***********MIDDLE*****/
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 0:
case 7:
{
putchar(' ');
draw(3,size);
putchar(' ');
break;
}
default:{
putchar(' ');
draw(1,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
/******DOWN**********/
for(j = 1 ; j <= size ; j++){
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 4:
case 3:
case 5:
case 7:
case 9:
{
putchar(' ');
draw(3,size);
putchar('|');
break;
}
case 6:
case 8:
case 0:
{
putchar('|');
draw(3,size);
putchar('|');
break;
}
default:
{
putchar('|');
draw(3,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
}
/*****FLOOR***********/
for(i = length-1 ; i >= 0 ; i--){
switch(digit[i]){
case 1:
case 4:
case 7:
{
putchar(' ');
draw(3,size);
putchar(' ');
break;
}
default:{
putchar(' ');
draw(1,size);
putchar(' ');
break;
}
}
if(i != 0)putchar(' ');
if(i == 0) putchar('\n');
}
/****************/
putchar('\n');
}
return 0;
}
706 WA - can anyone help me?
can anyone help me? I've tested and it works! =(
Code: Select all
#include<stdio.h>
#include<string.h>
#define TAM_NUM 9
void print0(int s, int *estado, int*cont){
switch(estado[0])
{
case 0:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[0]=1;
break;
}
case 1:
case 3:
{
printf("|");
for(int i=0; i<s; i++)
printf(" ");
printf("|");
cont[0]++;
if(cont[0]==s){
cont[0]=0;
if(estado[0]==1)
estado[0]=2;
else estado[0] = 0;
}
break;
}
case 2:
{
for(int i=0; i<s+2; i++)
printf(" ");
estado[0]=3;
break;
}
}
}
void print1(int s, int *estado, int*cont){
switch(estado[1])
{
case 0:
{
for(int i=0; i<s+2; i++)
printf(" ");
estado[1]=1;
break;
}
case 1:
{
for(int i=0; i<s+1; i++)
printf(" ");
printf("|");
cont[1]++;
if(cont[1]==s){
cont[1]=0;
estado[1]=0;
}
break;
}
}
}
void print2(int s, int *estado, int*cont){
switch(estado[2])
{
case 0:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[2]=1;
break;
}
case 1:
{
for(int i=0; i<s+1; i++)
printf(" ");
printf("|");
cont[2]++;
if(cont[2]==s){
cont[2]=0;
estado[2]=2;
}
break;
}
case 2:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[2]=3;
break;
}
case 3:
{
printf("|");
for(int i=0; i<s+1; i++)
printf(" ");
cont[2]++;
if(cont[2]==s){
cont[2]=0;
estado[2]=0;
}
break;
}
}
}
void print3(int s, int *estado, int*cont){
switch(estado[3])
{
case 0:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[3]=1;
break;
}
case 1:
{
for(int i=0; i<s+1; i++)
printf(" ");
printf("|");
cont[3]++;
if(cont[3]==s){
cont[3]=0;
estado[3]=0;
}
break;
}
}
}
void print4(int s, int *estado, int*cont){
switch(estado[4])
{
case 0:
{
for(int i=0; i<s+2; i++)
printf(" ");
estado[4]=1;
break;
}
case 1:
{
printf("|");
for(int i=0; i<s; i++)
printf(" ");
printf("|");
cont[4]++;
if(cont[4]==s){
cont[4]=0;
estado[4]=2;
}
break;
}
case 2:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[4]=3;
break;
}
case 3:
{
for(int i=0; i<s+1; i++)
printf(" ");
printf("|");
cont[4]++;
if(cont[4]==s){
cont[4]=0;
estado[4]=0;
}
break;
}
}
}
void print5(int s, int *estado, int*cont){
switch(estado[5])
{
case 0:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[5]=1;
break;
}
case 1:
{
printf("|");
for(int i=0; i<s+1; i++)
printf(" ");
cont[5]++;
if(cont[5]==s){
cont[5]=0;
estado[5]=2;
}
break;
}
case 2:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[5]=3;
break;
}
case 3:
{
for(int i=0; i<s+1; i++)
printf(" ");
printf("|");
cont[5]++;
if(cont[5]==s){
cont[5]=0;
estado[5]=0;
}
break;
}
}
}
void print6(int s, int *estado, int*cont){
switch(estado[6])
{
case 0:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[6]=1;
break;
}
case 1:
{
printf("|");
for(int i=0; i<s+1; i++)
printf(" ");
cont[6]++;
if(cont[6]==s){
cont[6]=0;
estado[6]=2;
}
break;
}
case 2:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[6]=3;
break;
}
case 3:
{
printf("|");
for(int i=0; i<s; i++)
printf(" ");
printf("|");
cont[6]++;
if(cont[6]==s){
cont[6]=0;
estado[6]=0;
}
break;
}
}
}
void print7(int s, int *estado, int*cont){
switch(estado[7])
{
case 0:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[7]=1;
break;
}
case 1:
{
for(int i=0; i<s+1; i++)
printf(" ");
printf("|");
cont[7]++;
if(cont[7]==s){
cont[7]=0;
estado[7]=2;
}
break;
}
case 2:
{
for(int i=0; i<s+2; i++)
printf(" ");
estado[7]=1;
break;
}
}
}
void print8(int s, int *estado, int*cont){
switch(estado[8])
{
case 0:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[8]=1;
break;
}
case 1:
{
printf("|");
for(int i=0; i<s; i++)
printf(" ");
printf("|");
cont[8]++;
if(cont[8]==s){
cont[8]=0;
estado[8]=0;
}
break;
}
}
}
void print9(int s, int *estado, int*cont){
switch(estado[9])
{
case 0:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[9]=1;
break;
}
case 1:
{
printf("|");
for(int i=0; i<s; i++)
printf(" ");
printf("|");
cont[9]++;
if(cont[9]==s){
cont[9]=0;
estado[9]=2;
}
break;
}
case 2:
{
printf(" ");
for(int i=0; i<s; i++)
printf("-");
printf(" ");
estado[9]=3;
break;
}
case 3:
{
for(int i=0; i<s+1; i++)
printf(" ");
printf("|");
cont[9]++;
if(cont[9]==s)
{
cont[9]=0;
estado[9]=0;
}
break;
}
}
}
int main()
{
int s;
char n[TAM_NUM];
bool v[TAM_NUM];
int estado[TAM_NUM], cont[TAM_NUM], tempEstado[TAM_NUM], tempCont[TAM_NUM];
scanf("%d", &s);
while( s!= 0)
{
for(int i=0; i<TAM_NUM; i++){
n[i]='\0';
v[i]=false;
estado[i]= cont[i] = 0;
}
getchar();
gets(n);
for(int i=0; i<TAM_NUM; i++) //marca os numeros que foram impressoas, resolve o probn
v[i] = false;
int indN = 0;
for(int i=0; i< 2*s+3; i++) //percorre as linhas
{
for(int j=0; j<strlen(n); j++) //percorre as colunas
{
int num = n[indN]-'0';
if(v[num]==false){
tempEstado[num] = estado[num];
tempCont[num] = cont[num];
v[num]=true;
}
else{
estado[num] = tempEstado[num];
cont[num] = tempCont[num];
}
switch(n[indN])
{
case '0': print0(s, estado, cont); break;
case '1': print1(s, estado, cont); break;
case '2': print2(s, estado, cont); break;
case '3': print3(s, estado, cont); break;
case '4': print4(s, estado, cont); break;
case '5': print5(s, estado, cont); break;
case '6': print6(s, estado, cont); break;
case '7': print7(s, estado, cont); break;
case '8': print8(s, estado, cont); break;
case '9': print9(s, estado, cont); break;
}
indN++;
if(indN==strlen(n)) printf("\n");
else printf(" ");
}
for(int i=0; i<TAM_NUM; i++) //marca os numeros que foram impressoas, resolve o probn
v[i] = false;
indN=0;
}
printf("\n");
scanf("%d", &s);
}
return 0;
}
Regards,
[]'s
Andre
[]'s
Andre