Guest User

Untitled

a guest
Mar 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. //
  2. // apple_orange.m
  3. //
  4. // To compile with clang
  5. // clang -framework Foundation apple_orange.m -o apple_orange
  6. //
  7. // Created by xuedong on 07/03/2018.
  8. //
  9.  
  10. #import <Foundation/Foundation.h>
  11.  
  12.  
  13. void countApplesAndOranges(int s, int t, int a, int b, NSArray *apples, NSArray *oranges) {
  14. int num_apples = 0;
  15. for (int apple_i = 0; apple_i < [apples count]; apple_i++) {
  16. if (a + [[apples objectAtIndex:apple_i] integerValue] >= s && a + [[apples objectAtIndex:apple_i] integerValue] <= t) {
  17. num_apples += 1;
  18. }
  19. }
  20.  
  21. int num_oranges = 0;
  22. for (int orange_i = 0; orange_i < [oranges count]; orange_i++) {
  23. if (b + [[oranges objectAtIndex:orange_i] integerValue] >= s && b + [[oranges objectAtIndex:orange_i] integerValue] <= t) {
  24. num_oranges += 1;
  25. }
  26. }
  27.  
  28. printf("%i\n", num_apples);
  29. printf("%i\n", num_oranges);
  30. }
  31.  
  32. int main(int argc, const char * argv[]) {
  33. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  34.  
  35. int s;
  36. int t;
  37. scanf("%i %i", &s, &t);
  38. int a;
  39. int b;
  40. scanf("%i %i", &a, &b);
  41. int m;
  42. int n;
  43. scanf("%i %i", &m, &n);
  44.  
  45. NSMutableArray *apples = [NSMutableArray array];
  46. int apple[m];
  47. for(int apple_i = 0; apple_i < m; apple_i++){
  48. scanf("%i", &apple[apple_i]);
  49. [apples addObject:[NSNumber numberWithInteger:apple[apple_i]]];
  50. }
  51. NSMutableArray *oranges = [NSMutableArray array];
  52. int orange[n];
  53. for(int orange_i = 0; orange_i < n; orange_i++){
  54. scanf("%i", &orange[orange_i]);
  55. [oranges addObject:[NSNumber numberWithInteger:orange[orange_i]]];
  56. }
  57.  
  58. countApplesAndOranges(s, t, a, b, apples, oranges);
  59.  
  60. [pool drain];
  61. return 0;
  62. }
Add Comment
Please, Sign In to add comment