In Chinese, "倒霉(dǎo méi)" refers to bad situations, especially those concerning with one's health, destiny or future. It is often used by people to relieve feelings after distress.
However, in ancient China, "倒霉(dǎo méi)" was not written in this way, and the meaning was different as well.
The story behind it can be traced back to China's "科举考试(kē jǔ kǎo shì, imperial exam) in the Ming Dynasty. At that time, it was rather difficult to pass the examination because the "八股取士(bā gǔ qǔ shì, eight-part essay examination) badly restricted intellectuals' full plethora of knowledge, and many of them tended to cheat on the exam. Therefore, the candidate for the imperial exam would usually erect a flagpole which was called "楣(méi, lintel over the door)" in front of the door before taking the exam. The candidate would also hang a flag with the Chinese character "捷(jié, triumph or victory)" on the flag for good luck.
If the candidate passed the exam, the pole would still be standing, and another yellow pole with a yellow flag would be set up openly displayed. If the candidate failed, the pole would be put down, and that was called "倒楣(dǎo méi)", literally meaning falling lintel.
But why does the original word "倒楣(dǎo méi)" become "倒霉(dǎo méi)"? The single character "楣" originally refers to the lintel over a door while it stands for "pole" in the phrase "倒楣(dǎo méi)". Then "倒楣(dǎo méi)" gradually developed into the dialect of Taizhou, Zhejiang, indicating disadvantage or bad luck.
The weather is always humid and rainy across Yangtze river regions. During rainy season, the dry and salty preserved food can easily get moldy (霉变-méi biàn/发霉-fā méi). This food would be thrown away, which is called "倒霉(dǎo méi)" in Chinese. As "楣(méi)" and "霉(méi)" are pronounced exactly the same, and "霉(méi)" also indicates bad luck. In this way, "倒楣(dǎo méi)" gradually developed into "倒霉(dǎo méi)".