See this link to a post on a related subject:-
http://www.theanswerb.../Question1058531.html
It sounds like your laptop power connector has an intermittent connection. Unfortunately although this is most likely due to a solder connection breaking away from the PCB, the cost to repair (which involves dismantling the case) is not cheap.
Are you certain that the problem is not due to the adapter connection failing and the battery running down to the point where the laptop switches off?
Otherwise it could be as a result of the above, plus an intermittent battery connection (as in the above post).