I am not asking the code.But I am just asking with the logic.I have been thinking of this for the past 3 days but couldnt get a logic for implementing this.
What do you mean by "I've got a line"? If you mean you've cout'ed all of that, then there probably isn't a way for any system to just read that and rearrange it.
However, it could work if you had something like an array.