|
Prev: Extract directory from filename
Next: One way hash?
From: akar on 3 Jul 2008 17:38 I have strings (start and cont) and numbers (0,1,2,3....) Each string has a number. once the string started ( with its number) it becomes a line until new Start string occures for a defined numer. i.e. start 0 , L1 cont 0 , L1 cont 0 , L1 start 1 , L2 cont 1 , L2 cont 0 , L1 start 0 , L3 cont 0 , L3 cont 1 , L2 cont 0 , L3 start 2 , L4 start 0 , L5 ....... how to create an alghoritm for this? any idea?
From: Daniel T. on 3 Jul 2008 18:26 In article <g4jgtg$d6n$1(a)news.onet.pl>, "akar" <geoart(a)wp.p> wrote: > I have strings (start and cont) and numbers (0,1,2,3....) > Each string has a number. once the string started ( with its number) it > becomes a line until new Start string occures for a defined numer. > i.e. > start 0 , L1 > cont 0 , L1 > cont 0 , L1 > start 1 , L2 > cont 1 , L2 > cont 0 , L1 > start 0 , L3 > cont 0 , L3 > cont 1 , L2 > cont 0 , L3 > start 2 , L4 > start 0 , L5 > ....... > how to create an alghoritm for this? any idea? What should the output be using the above as input?
From: Jim Langston on 3 Jul 2008 23:53 "akar" <geoart(a)wp.p> wrote in message news:g4jgtg$d6n$1(a)news.onet.pl... >I have strings (start and cont) and numbers (0,1,2,3....) > Each string has a number. once the string started ( with its number) it > becomes a line until new Start string occures for a defined numer. > i.e. > start 0 , L1 > cont 0 , L1 > cont 0 , L1 > start 1 , L2 > cont 1 , L2 > cont 0 , L1 > start 0 , L3 > cont 0 , L3 > cont 1 , L2 > cont 0 , L3 > start 2 , L4 > start 0 , L5 > ....... > how to create an alghoritm for this? any idea? This is actually fairly trivial since there are only 2 possibilities, start or cont. And it looks like we don't even care about cont, because if it's not start, then it is. So something like (pseudo code) while ( get input ) { if ( first 5 chars of string == "start" ) { // is new entry/line/whatver } else if ( first 5 chars of strig == "cont " { // is continuation } else { // Error on input, not "start" or "cont " } } Actual code depends on a number of things, main one being, C or C++? Second being, how are you getting your input, etc? The algorithm is fairly simple though
From: akar on 4 Jul 2008 16:26 >I have strings (start and cont) and numbers (0,1,2,3....) > Each string has a number. once the string started ( with its number) it > becomes a line until new Start string occures for a defined numer. > i.e. > start 0 , L1 > cont 0 , L1 > cont 0 , L1 > start 1 , L2 > cont 1 , L2 > cont 0 , L1 > start 0 , L3 > cont 0 , L3 > cont 1 , L2 > cont 0 , L3 > start 2 , L4 > start 0 , L5 > ....... > how to create an alghoritm for this? any idea? ====================================================== Ok, what about if I want to start 5 new strings and then continue every line in different combinnations? i.e. start 0 - L1 start 1 - L2 start 2 - L3 start 3 - L4 start 4 - L5 cont 2 - L3 cont 0 - L1 cont 2 - L3 ....... then I could start another strings with numer that recurrents ( to start new line) start 0 - L6 cont 1 - L2 .... basically, if the string is Start and it has a number assigned, this creates a Line. It can happen that I can starn another Line with the same number but new Line should be incremented: start 0 - L1 cont 0 - L1 start 0 - L2 cont 0 - L2 I would need an alghoritm for multiple lines occurrences. hope this helped :) Ps. Input is String (Start, Cont) and Number (0,1,2,3....) Output is a line (L1, L2, L3....) for a countless combintions of String and numbers. Thanks akar
From: Daniel T. on 4 Jul 2008 17:48
In article <g4m11p$ej2$1(a)news.onet.pl>, "akar" <geoart(a)wp.p> wrote: > >I have strings (start and cont) and numbers (0,1,2,3....) > > Each string has a number. once the string started ( with its number) it > > becomes a line until new Start string occures for a defined numer. > > i.e. > > start 0 , L1 > > cont 0 , L1 > > cont 0 , L1 > > start 1 , L2 > > cont 1 , L2 > > cont 0 , L1 > > start 0 , L3 > > cont 0 , L3 > > cont 1 , L2 > > cont 0 , L3 > > start 2 , L4 > > start 0 , L5 > > ....... > > how to create an alghoritm for this? any idea? > > ====================================================== > > Ok, what about if I want to start 5 new strings and then continue every line > in different combinnations? i.e. > start 0 - L1 > start 1 - L2 > start 2 - L3 > start 3 - L4 > start 4 - L5 > cont 2 - L3 > cont 0 - L1 > cont 2 - L3 > ...... > then I could start another strings with numer that recurrents ( to start new > line) > start 0 - L6 > cont 1 - L2 > ... > basically, if the string is Start and it has a number assigned, this creates > a Line. It can happen that I can starn another Line with the same number but > new Line should be incremented: > start 0 - L1 > cont 0 - L1 > start 0 - L2 > cont 0 - L2 > I would need an alghoritm for multiple lines occurrences. > > hope this helped :) > > Ps. Input is String (Start, Cont) and Number (0,1,2,3....) > Output is a line (L1, L2, L3....) for a countless combintions of > String and numbers. Well, the point of this group is to help you learn. So here is something to get you started... The first, and often hardest thing is to come up with an interface, so I'll give you that: vector<string> breakLines( istream& is ) { vector<string> result; // insert code here return result; } int main() { { istringstream in( "start 0 - L1\n" ); vector<string> lines = breakLines( in ); assert( lines.size() == 1 ); assert( lines[0] == "L1" ); cout << "Great job!\n"; } } Now insert code into the function to make the program print "Great job!". Once you get get that working, report back here with what you did so we can take the next step. (For the record, I wrote a function that does the job with only 3 linearly independent paths.) |