Last active
August 30, 2016 15:24
-
-
Save AnthonyBY/0f7a56b952a3a5aff49d830a22392b10 to your computer and use it in GitHub Desktop.
Objective-C templates (snippets) for solve problems on 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
// Example of using code for HackerRanks | |
// Input and Output array and methods | |
#import <Foundation/Foundation.h> | |
@interface Solution : NSObject | |
+ (NSArray *)calculateDeltaEncoding:(NSArray *)numbers; | |
@end | |
@implementation Solution | |
+ (NSArray *)calculateDeltaEncoding:(NSArray *)numbers { | |
//enter your solution here: | |
return nil; | |
} | |
@end | |
int main() { | |
@autoreleasepool { | |
//Example for methods used | |
[Solution calculateDeltaEncoding:nil]; | |
// Read String before whitespace | |
NSString *word; | |
char* word_temp = (char *)malloc(512000 * sizeof(char)); | |
scanf("%s",word_temp); | |
word = [NSString stringWithFormat:@"%s", word_temp]; | |
// Read String with whitespaces | |
NSString *word; | |
char* word_temp = (char *)malloc(512000 * sizeof(char)); | |
scanf("%[^\n]s",word_temp); | |
word = [NSString stringWithFormat:@"%s", word_temp]; | |
//Read an array of int | |
int n; | |
scanf("%d",&n); | |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:n]; | |
for(int i = 0; i<n; i++) { | |
int inputElement = 0; | |
scanf("%d", &inputElement); | |
[array addObject:[NSNumber numberWithInteger:inputElement]]; | |
} | |
//NSLog (print) array of int | |
for(int i=0; i<n; i++) { | |
printf("%i\n", [[array objectAtIndex:i] intValue]); | |
} | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment