Using unary representation with addition java string -


i need write code takes string input , turns it, or effect, valid unary equation addition verify if valid. i'm confused, point me in direction of understanding this? example be: 111+1111=11111+1+1 statement 3+4=5+1+1 valid. other question how use stacks unary operations.

if limited language can write simple parser using number of methods. can first split string

string[] parts = eqn.split("="); 

then split each part:

string[] left = parts[0].split("\\+"); string[] right = parts[1].split("\\+"); 

now can count lengths of strings:

int leftside = 0; (string l : left) {     leftside += l.length; } 

and on right side , see if equal.

there many other ways can tackle this.

basically have write parser. might want use character-by-character scanner, or use regexes or generic tool such antlr. depends on final goal , whether change. have characters other 1, +, =, example?

my guess homework. , guess expected read character-by-character , push() each character on stack. have pop() stack when encounter conditions.i'm not going you...


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -