Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
int numberOfIntegers = 0;
scanf("%d", &numberOfIntegers);
int difference = 0;
scanf("%d", &difference);
NSMutableSet *set = [NSMutableSet setWithCapacity:10000];
int total = 0;
for (int i = 0; i < numberOfIntegers; i++) {
long number = 0;
scanf("%ld", &number);
long remainder = 0;
if (number > difference) {
remainder = number - difference;
if ([set containsObject:[NSNumber numberWithLong:remainder]]){
total++;
}
}
remainder = difference + number;
if ([set containsObject:[NSNumber numberWithLong:remainder]]){
total++;
}
[set addObject:[NSNumber numberWithLong:number]];
}
printf("%d",total);
}
return 0;
}
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.