Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HackerRank: Pangram
//
// 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;
}
@nbarnold01

This comment has been minimized.

Copy link
Owner Author

commented Nov 1, 2015

Uses NSSets to check if a string is a pangram.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.