Last active
December 2, 2016 21:04
-
-
Save jakehawken/67150f7acd4521db355b to your computer and use it in GitHub Desktop.
Objective-C solution boilerplate for HackerRank
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
#import <Foundation/Foundation.h> | |
@interface Solver : NSObject | |
- (void)findSolutionForInput: (NSArray)input; | |
@end | |
@interface Solver() | |
{ | |
} | |
@end | |
@implementation Solver | |
- (void)findSolutionForInput: (NSArray*)input | |
{ | |
NSString *solution = @"Solution!"; | |
//PRINTING AN NSSTRING | |
printf("%s", [solution UTF8String]); | |
} | |
@end | |
int main (int argc, const char * argv[]) | |
{ | |
@autoreleasepool | |
{ | |
Solver *solver = [[Solver alloc] init]; | |
//GETTING AN INTEGER | |
int numberOftestCases; | |
scanf("%i", &numberOftestCases); | |
/* you can also do it with NSInteger like this | |
NSInteger testCases; | |
scanf("%ld", &testCases); | |
*/ | |
for (int i=0; i<numberOftestCases; i++) | |
{ | |
NSMutableArray *solutionArray = [NSMutableArray array]; | |
//GETTING A STRING | |
int stringLength; | |
scanf("%d", &stringLength); //anytime hacker rank is going to give you a string, they'll give you its length fist | |
char text[stringLength + 1]; | |
scanf("%s", text); | |
NSString *row = [[NSString alloc] initWithBytes:text length:stringLength encoding:NSUTF8StringEncoding]; | |
[solutionArray addObject: row]; | |
//GETTING SPACE-SEPARATED VALUES ON A SINGLE LINE | |
NSInteger first; | |
NSInteger second; | |
scanf("%ld %ld", &first, &second); //you can do this with int as well, just change the scan f to use %i | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment