Last active
July 26, 2020 01:50
-
-
Save orkoden/c811fc0364651d5ac1f5 to your computer and use it in GitHub Desktop.
Hackerrank.com Boilerplate template for reading from STDIN and writing to STDOUT for Objective-C
This file contains hidden or 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 HRSTDIOReadWriter : NSObject | |
@end | |
@implementation HRSTDIOReadWriter | |
+(NSString*) readFromSTDIN | |
{ | |
NSFileHandle *kbd = [NSFileHandle fileHandleWithStandardInput]; | |
NSData *inputData = [kbd readDataToEndOfFile]; | |
NSString *inputString = [[NSString alloc] initWithData:inputData | |
encoding:NSUTF8StringEncoding]; | |
return inputString; | |
} | |
+ (void) writeToSTDOut:(NSString*) outputString | |
{ | |
NSFileHandle *stdOut = [NSFileHandle fileHandleWithStandardOutput]; | |
NSData* outData = [outputString dataUsingEncoding:NSUTF8StringEncoding]; | |
[stdOut writeData:outData]; | |
} | |
@end | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
[HRSTDIOReadWriter writeToSTDOut:[HRSTDIOReadWriter readFromSTDIN]]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this works, but I really suggest going about this way: http://stackoverflow.com/questions/27607925/how-to-solve-hackerrank-problems-in-objective-c &Thanks.