110 likes | 237 Views
Numpad. 30th January, 2010. Statistics. #Max = 15 Mean (attempted) = 49.7 . How do you solve this question?. How long did you take?. >1hr? 45 min? 30 min? 20 min? 15 min? 10 min? 5 min? 1 min?. Aim. Test your programming skills if for Use of suitable data types char int
E N D
Numpad 30th January, 2010
Statistics • #Max = 15 • Mean (attempted) = 49.7
How long did you take? • >1hr? • 45 min? • 30 min? • 20 min? • 15 min? • 10 min? • 5 min? • 1 min?
Aim • Test your programming skills • if • for • Use of suitable data types • char • int • array • Carefulness • hardcode
Observation • Decision does not depend on future presses • ‘Causal’ • Analyzing the sequence would not help • So we can just simulate!
Skills • Reading the number • The question says ‘a positive integer N, which is less than 1030.’ • How do I know how large is the number? (When to stop input?) • while scanf()... • while cin >> • while not eoln do
Use of data types • Array • What size? • How to access an array? • What index to use? • Char • How to convert to integer? • Integer
Carefulness • If conditions • When to use the left zero / right zero? • How to determine the distance? • Formula? • Hardcode?
Formula • Steps = Steps in horizontal direction (dx) + Steps in vertical direction (dy) • dx = abs(prev % 3 – cur % 3) • dy = abs((prev-1) \ 3 – (cur-1) \ 3) • Zero is left for you to think