![]() |
|
#1
|
|||
|
|||
justifying text with dynamic programminghi everyone
im working on a program to justify text but it has to be done using dynamic programming so that the program finds the optimal number of words to put on each line by reading in from a text file. the only thing that i need left to build is the string format paragraph function. right now im using a vector of vecors table but i was told that all i reall need is just a 1d vector. my problem is, with what i have now how do i convert it to a 1d vector heres what i have so far CPP / C++ / C Code:
Last edited by LuciWiz : 03-Feb-2005 at 01:29.
Reason: Please insert your C code between [c] & [/c] tags
|
|||
|
#2
|
|||
|
|||
|
Quote:
In the first place: where is the program specification? Is inter-word spacing relevant (multiple spaces treated as single spaces or what)? How would you handle tab characters? Anything else I should know? I didn't really try to analyze your actual cost calculations and formatting, since I don't know what it is supposed to be trying to do. Saying "all you really need is just a 1D vector" means nothing. That's like saying, "all you really nead is the text processing program TeX." In fact, all you really need is a string: Read the entire paragraph into a string and then performing line-breaking iteratively: Go through the string multiple times, experimentally moving the line breaks, and keeping track of total cost for each iteration. Keep the best effort in a separate string or something like that. Instead of a string, you could use a 1-D vector of strings (the words) so that multiple passes through the paragraph would not have to break the string into words every time (but that depends on spacing and tab considerations that I mentioned). By the way, the program you posted is obviously defective. Here are a few things I noticed: This line is incorrect (inttext_width needs a type specifier). CPP / C++ / C Code:
Furthermore, the function uses text_width, not inttext_width. Oh --- now I see --- it should be CPP / C++ / C Code:
Furthermore the function is declared as returning a string but returns nothing. Furthermore the penalty calculation use the variable "space", but the variable is never given a value. Now these makes no sense to me; maybe you can explain: CPP / C++ / C Code:
What are these trying to do? They look as though they are defining vectors of vectors and trying to intialize with two ints --- or what? Regards, Dave |
|
#3
|
|||
|
|||
|
thanx for the response dave
inter word spacing is suppose to be taken into consideration but that is the only thing as far as spacing. no tab and new paragraph is already done yes i am looking to put this into a 1-d vector of strings and yes it is pretty much like the text formatting program TeX. as far as the vector< vector<int> > penalty (n,n) all that is saying is an n number of int with an n size. but that is what i want to get rid of by creating a single vector oh and the var "space" is the inter word spacing i put that mainly in there as a reminder because i have yet figured out how to actually calculate it thanx for the help |
|
#4
|
|||
|
|||
|
Quote:
If you want a vector strings with an initial size of n strings, for example just use: CPP / C++ / C Code:
It's still dynamic, and it can be increased or decreased in size by member functions. (And the formatting is more like Microsoft Word, since Word does it a paragraph at a time, and Tex does it a page at a time --- that's why Tex blows the doors off of Word and other "word" processors as far as quality of output.) Regards, Dave |
|
#5
|
|||
|
|||
|
kewl thanx dave
but if i wanted to create a 1d vector out of the existing code i already have how would i do that or would i need to recode everthing? |
|
#6
|
|||
|
|||
|
Quote:
Since your existing code doesn't work (won't compile; function format_paragraph() doesn't return anything, etc.) I'm not sure how to answer that. In particular, I haven't tried to see exactly what your format_paragraph() is doing, so I couldn't comment on changes. Regards, Dave |
|
#7
|
|||
|
|||
|
can someone help me out in developing the program then?
|
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| burning problems PLEASE PLEASE HELP | kelticeire | Computer Hardware Forum | 4 | 01-Dec-2006 16:39 |
| saving html text | dopee | MySQL / PHP Forum | 1 | 17-Jan-2005 05:15 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 11:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The