Solved

Display

Posted on 2004-04-27
9
216 Views
Last Modified: 2012-05-04
write a program that displays numbers in an LC-display-like style on the computer.
Input  
The input file contains several lines, one for each number to be displayed. Each line contains two integers s, n (  1<=s<=10, 0<=n<=999999 ), where n is the number to be displayed and s is the size in which it shall be displayed.
The input file will be terminated by a line containing two zeros. This line should not be processed.
Output  
Output the numbers given in the input file in an LC-display-style using s ``-'' signs for the horizontal segments and s ``|'' signs for the vertical ones. Each digit occupies exactly s+2 columns and 2s+3 rows. (Be sure to fill all the white space occupied by the digits with blanks, also for the last digit.) There has to be exactly one column of blanks between two digits.
Output a blank line after each number. (You will find a sample of each digit in the sample output.)





Sample Input  
2 12345
3 67890
0 0
Sample Output  
      --   --        --
   |    |    | |  | |  
   |    |    | |  | |  
      --   --   --   --
   | |       |    |    |
   | |       |    |    |
      --   --        --

 ---   ---   ---   ---   ---
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   ---      
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---

0
Comment
Question by:krithi
9 Comments
 
LVL 3

Expert Comment

by:CoolBreeze
Comment Utility
Sorry, krithi, it is against the charter of this site for you to ask this type question, and it is also against the rules for any experts to help you.
Please re-read the membership agreement:
http://www.experts-exchange.com/jsp/memberAgreement.jsp
Pay particlular attention to this section:
perhaps it would be more helpful if you state what your problem is.

0
 

Author Comment

by:krithi
Comment Utility
i don need any code dude all i wan is little bit help or psuedocode
0
 
LVL 3

Accepted Solution

by:
CoolBreeze earned 84 total points
Comment Utility
oops, that was a mispost. but nevertheless, as I said it would be more helpful if you state what your problem is. Without stating what the problem is, it sounds more like a homework question.

regarding the problem, a easy way out is to initialize a 2D array, with each element representing the real display. if the element contains 0, draw a space, contains 1 draw a '-', contains 2 draw a '|'. that is the simple way out though not the only way out.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:krithi
Comment Utility
Can anyone give me more details.

thnx
krithi
0
 
LVL 39

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 83 total points
Comment Utility


CoolBreeze's 2D array is the way to go.


Basically have a static array of how many digits you need.  

Then have a function for each number:

IE:

Draw_one

Draw_two


and mark everything in the array.

Then you just need to output the array.

0
 
LVL 4

Assisted Solution

by:skypalae
skypalae earned 83 total points
Comment Utility
Hi guys,
this doesn't look like HW to me .. more it looks like ACM programming contest :)

anyway .. the algorithm you can use 2dim array simulating the dot matrix display (as ged pointed) or you can use some more sophisticated algorithm.

// you get this line, don't you? it's just your digital representation of number 0 (followed by number 1 etc.)
char *n0[9] = {" --- ", "|   |", "|   |", "|   |", "     ", "|   |", "|   |", "|   |", " --- "} ;
char *n1[9] .....
....

// this is just array of all numbers
char *n[][] = {n0, n1, n2, n3, n4 ...... n9} ;

// now display every line of segment display:
for (i=0; i<9; i++)
    // and in every line treat all numbers
    for (j=0; j<strlen(numberstring); j++)
        // and here just display correct line of correct number
        printf ("%s", n[numberstring[j]][i]) ;
    printf ("\n") ;


----------------------------------------------

i just read your post correctly and found out the size parameter .. ok, there are 2 solutions. or you predefine the strings for all sizes, or you use some algorithm for the string creation in runtime. Following algorithm can be used

// top segment, top side segments, middle segment, bottom side segments, bottom segment
char *n0[] = {" - ", "| |", "   ", "| |", " - "} ;

1st line:
print 1st char of top (" ")
#s print 2nd char
print 3rd char

topside lines:
print 1st char of topside
#s print 2nd char
print 3rd char

middle:
...
etc, etc

Cheers! S.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now