Created
November 1, 2015 11:04
-
-
Save nbarnold01/4d34bd2c3adc3bb019a1 to your computer and use it in GitHub Desktop.
HackerRank: Pangram
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
// | |
// main.m | |
// Pangrams | |
// | |
// Created by Nathan Arnold on 10/31/15. | |
// Copyright © 2015 Nathan Arnold. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
// insert code here... | |
NSSet *lowerCaseChars = [NSSet setWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",nil]; | |
NSMutableSet *lettersInString = [NSMutableSet setWithCapacity:26]; | |
NSMutableCharacterSet *alphaCharSet = [[NSMutableCharacterSet alloc]init]; | |
[alphaCharSet formUnionWithCharacterSet:[NSCharacterSet lowercaseLetterCharacterSet]]; | |
[alphaCharSet formUnionWithCharacterSet:[NSCharacterSet uppercaseLetterCharacterSet]]; | |
char c; | |
while (scanf(" %c",&c)!=EOF) { | |
if ([alphaCharSet characterIsMember:c]){ | |
NSString *string = [NSString stringWithFormat:@"%c" , c]; | |
[lettersInString addObject:[string lowercaseString]]; | |
} | |
} | |
if ([lowerCaseChars isEqualToSet:lettersInString]){ | |
printf("pangram"); | |
} else { | |
printf("not pangram"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses NSSets to check if a string is a pangram.