English 中文(简体)
最高 4 个数字, 从数组 # 1 到另一个数组的存储
原标题:Highest 4 Numbers From Array #1 To Store In Another Array

我这里有三个不同的阵列...

我环绕高尔夫三联赛(NSmubableAray), 并试图将最高4个结果(golfer三联赛以#s 字符串形式)存储到顶部四联赛(NSmubableAray), 然后我计划将最高数字的代号存储在数组顶部四联赛(NS MubableAray)中。

一个棘手的问题是,高尔夫三连队在99岁就出局了, 但我希望它表现得像零一样。 所以99号不应该被加到两个阵列中...

Example: golferThreeIcons {2,1,5,3,9}

环环经过后,我想让它显示像这样的东西...

{0, 2, 3, 4} - - - 0 等于 2 高尔夫三连 - - 2 等于 5 等于 3 个高尔夫三个图标

{2, 5, 3, 9} - -(只要与前四个图标 id对应,则以任何顺序排列)

NSMutableArray *topFourIconsId = [NSMutableArray arrayWithObjects: @"0", @"0", @"0", @"0", @"0" ,nil];
NSMutableArray *topFourIconsNum = [NSMutableArray arrayWithObjects: @"0", @"0", @"0", @"0", @"0" ,nil];
int *ids = 0;
                for (NSString *s in golferThreeIconCounter) {
                    if(s != @"0") {
                        int sint = [s intValue];
                        int *idn = 0;
                        for(NSString *n in topFourIconsNum) {
                            int nint= [n intValue];
                            if(sint == 99 && nint == 0) {
                                NSString *idstring = [NSString stringWithFormat:@"%d", ids];
                                NSString *sintstring = [NSString stringWithFormat:@"%d", sint];
                                [topFourIconsId replaceObjectAtIndex:idn withObject:idstring];
                                [topFourIconsNum replaceObjectAtIndex:idn withObject:sintstring];
                                NSLog(@"IN %@",sintstring);
                                break;
                            }
                            else {
                                if (sint > nint) {
                                    NSString *idstring = [NSString stringWithFormat:@"%d", ids];
                                    NSString *sintstring = [NSString stringWithFormat:@"%d", sint];
                                    [topFourIconsId replaceObjectAtIndex:idn withObject:idstring];
                                    [topFourIconsNum replaceObjectAtIndex:idn withObject:sintstring];
                                    NSLog(@"IN %@",sintstring);
                                    break;
                                }
                            }
                            idn++;
                        }
                    }
                    ids++;
                }
最佳回答

只是个疯狂的主意

将您的高尔夫三连队以数组索引作为键,将数组数值作为值,然后按其值对键进行排序:

NSDictionary *dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"2", @"1", @"5", @"3", @"9", nil] forKeys:[NSArray arrayWithObjects:@"0", @"1", @"2", @"3", @"4", nil]];
NSArray *sortedKeys = [dict keysSortedByValueUsingSelector:@selector(caseInsensitiveCompare:)];

NSLog([sortedKeys description]);
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签