String - Partial Reverse (First Characters - Alphabets)

So here is another problem that i just thought of. This problem is best done with stacks. So the problem is basically to let the user enter a string and then the first series of alphabets should be reversed. Here are some examples.

eg1:

Original: Hello World

Result: olleH World

eg2:

Original: text123

Result: txet123

eg3:

Original: -hello

Result: -hello


Meaning, the reverse will only proceed if the first series of characters are alphabets

So the concept for the solution would be,

  1. If recognize a character from the start, push the token to the stack

  2. If not, pop and display everything from the stack and concatinate with the remaining
    tokens.

These are the only steps needed.

Introducing, THE CODE:

4 comments:

Anonymous said...

why did you declare the token variable inside the loop???
what pakage does the stack methods belong to???

-javaluvers99-

Anonymous said...

can you make a source code for this problem???

write a program that will accept a string and check whether a word has been repeated in the string entered...

-javaluvers99-

Tyanak said...

the purpose for the loop is basically for the reading of each character of the string. Its actually okay for the token to be read inside the loop since it won't have that much effect except for the allocation withing the memory.

about the repeated word, yeah its possible, but what implementation do you want me to solve it with? its possible simply by reading each character in the string and comparing it with the string. we'll just check for repeated letters then check for the sequence. i just want to know what implementation you want it to be.

Tyanak said...

well, maybe within this week, i'll be able to post such problem, maybe in Java then i'll try it with assembly language.

Post a Comment