Done prob12 in cpp