B speed: 180/8- 18=4.5.
Twenty seconds after the train leaves A, it meets the oncoming B. At this time, the distance between A and B is18 * 20+180-6 * 20 = 420m.
420/(6+4.5)= 40 seconds before they met. Throw away the next 8 seconds, 40-8=32 seconds, and the two meet after 32 seconds.