Created
November 9, 2015 15:50
-
-
Save nbarnold01/1e6b2050f80926f8b67b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// Sherlock and the Beast | |
// | |
// Created by Nathan Arnold on 11/9/15. | |
// Copyright © 2015 Nathan Arnold. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
/* | |
A Decent Number has the following properties: | |
3, 5, or both as its digits. No other digit is allowed. | |
Number of times 3 appears is divisible by 5. | |
Number of times 5 appears is divisible by 3. | |
*/ | |
void printFivesAndThrees(int fives, int threes) { | |
for (int i = 0; i< fives; i++){ | |
printf("5"); | |
} | |
for (int i = 0; i< threes; i++){ | |
printf("3"); | |
} | |
printf("\n"); | |
} | |
void processTestCase() { | |
int numberOfDigits = 0; | |
scanf("%d", &numberOfDigits); | |
if (numberOfDigits >= 3){ | |
//Integer division lops off the remainder | |
int maxNumOfFives = numberOfDigits/3; | |
//loop through, look at remainder each time, | |
//remainder | |
if (numberOfDigits % 3 == 0) { | |
printFivesAndThrees(numberOfDigits, 0); | |
} else if (numberOfDigits == 5) { | |
printFivesAndThrees(0, numberOfDigits); | |
} else { | |
while (maxNumOfFives > 0) { | |
//Number of digits left | |
int remainingDigits = (numberOfDigits - (maxNumOfFives * 3)); | |
if (remainingDigits % 5 == 0) { | |
//mod is number of fives | |
//maxNumOfThrees is number of Threes | |
printFivesAndThrees(maxNumOfFives*3, remainingDigits); | |
return; | |
} else { | |
maxNumOfFives -= 1; | |
} | |
} | |
if (numberOfDigits %5 == 0) { | |
printFivesAndThrees(0, numberOfDigits); | |
} else { | |
printf("-1\n"); | |
} | |
} | |
} else { | |
printf("-1\n"); | |
} | |
} | |
int main(int argc, const char * argv[]) { | |
// @autoreleasepool { | |
// insert code here... | |
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; | |
int numberOfTestCases = 0; | |
scanf("%d", &numberOfTestCases); | |
for (int i = 0; i < numberOfTestCases; i++){ | |
processTestCase(); | |
} | |
// } | |
// [pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment