I dont know if there's any thing wrong in the question but it clearly says " how many times u write 5 ". So that means 55 is counted as 2 times , 555 as 3 times and so on. So the answer should be 300 times ( 100 times in units position , 100 times in tens position ,100 times in hundreds position) .
If the question was how many integers in 1-1000 contain the digit 5, then 271 is correct.