I guess my logic is correct can u see and tell the mistake please output is not coming
In the for loop that iterates over string, instead of <=, use <. Moreover you need to take a temp string input using getline after n so that input moves to next line
Corrected Code