有100个数,每个数的取值范围是[20 55], 找出其中的重复的数,重复的次数.
NSCountedSet *set = [NSCountedSet setWithCapacity:100];
for (int i = 0; i < 10; i++) {
int random = arc4random() % (55 - 20 + 1) + 20;
printf("%d ", random);
[set addObject:@(random)];
}
for (NSNumber *num in set) {
NSUInteger count = [set countForObject:num];
if (count > 1) {
printf("\n");
printf("%d : %lu\n",[num intValue], count);
}
}