Computer Science Canada Upside Down Number |
Author: | tyronefrancis01 [ Fri Jun 03, 2016 9:11 pm ] |
Post subject: | Upside Down Number |
hello guys im trying to write a program that is rotated 180 degrees on the page (turned upside down). A multi-digit number may also look like itself when rotated on the page; for example 9966 and 10801 do, but 999 and 1234 do not. Sample input: 108801 Output: 108801 is rotatable Sample input: 69 Output: 1008 is not rotatable Help me pls! thank you so much |
Author: | Zren [ Sun Jun 05, 2016 11:34 pm ] |
Post subject: | RE:Upside Down Number |
What have you tried so far? Try breaking the larger problem down into smaller goals like so. 1) First, on paper, write down each digit, then write what digit it looks like reversed, or if there isn't any digits it looks like. 2) Then write a function that accepts two parameters, and results true or false depending on if the second parameter is the reverse of the second parameter. Eg: func isReversedDigit(a:string, b:string) : bool put isReversedDigit("6", "9") should output true. put isReversedDigit("3", "9") should output false. 3) Use substrings to get the character at a specific index. 4) Use a single loop to compare the first and last digit, then the second and second last digit, then the third and third last digit... etc either until you've compared the entire string. |