Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #import <Foundation/Foundation.h>
  2.  
  3. int main(int argc, const char * argv[]) {
  4. @autoreleasepool {
  5.  
  6. // All our string goodies:
  7. NSString *onThe = @"\nOn the ";
  8. NSArray *ordinalNumbers = @[@"first ", @"second ", @"third ", @"fourth ",
  9. @"fifth ", @"sixth ", @"seventh ", @"eighth ",
  10. @"ninth ", @"tenth ", @"eleventh ", @"twelfth "];
  11. NSString *dayOf = @"day of Christmas my true love gave to me \n";
  12. NSString *allGifts = @"and ";
  13. NSArray *gifts = @[@"a Partridge in a Pear Tree.\n", @"Two Turtle Doves\n",
  14. @"Three French Hens,\n", @"Four Calling Birds,\n",
  15. @"Five Gold Rings,\n", @"Six Geese a-Laying,\n",
  16. @"Seven Swans a-Swimming,\n", @"Eight Maids a-Milking,\n",
  17. @"Nine Ladies Dancing,\n", @"Ten Lords a-Leaping,\n",
  18. @"Eleven Pipers Piping,\n", @"Twelve Drummers Drumming,\n"];
  19.  
  20. // Loop 12 times
  21. for (int i = 0; i < 12; i++) {
  22.  
  23. // Print the first line with the correct ordinalNumber
  24. printf("%s%s%s", [onThe UTF8String], [ordinalNumbers[i] UTF8String], [dayOf UTF8String]);
  25.  
  26. // Print current gift
  27. printf("%s", [gifts[i] UTF8String]);
  28.  
  29. // On iterations 2-12, print prior gifts
  30. if (i > 0) {
  31. printf("%s", [allGifts UTF8String]);
  32. }
  33.  
  34. // Construct the NSString here that will contain all the gifts up to now
  35. // for use in the next iteration
  36. if (i == 0) {
  37. allGifts = [allGifts stringByAppendingString:gifts[i]];
  38. } else {
  39. allGifts = [gifts[i] stringByAppendingString:allGifts];
  40. }
  41. }
  42.  
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement