NSArray *tmp = @[@[@(1), @(2), @(3), @(4), @(5)],
@[@(6), @(7), @(8), @(9), @(10)],
@[@(11), @(12), @(13), @(14), @(15)],
@[@(16), @(17), @(18), @(19), @(20)],
@[@(21), @(22), @(23), @(24), @(25)]];
int count = [tmp count];
for (int num = 0; num <= 2*(count-1); num++) { // 遍历总的次数
NSMutableArray *tmpArray = [NSMutableArray array];
for (int j=0; j<count; j++) {
if ( (num-j)<0) { // 如果遍历的次数小于总行号, 直接跳出循环
break;
}
if(num-j+1 > count){ // 如果越界, 则跳出本次循环
continue;
}
[tmpArray addObject:tmp[num - j][j]];
}
NSLog(@"Array = %@", tmpArray);
}
时间: 2024-11-05 11:48:35