#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSArray *arr3=@[@{@"name":@"Tim Cook",@"age":@"24",@"sex":@"female",@"score":@"89"},@{@"name":@"Jony Ive",@"age":@"26",@"sex":@"female",@"score":@"76"},@{@"name":@"Steve Jobs",@"age":@"24",@"sex":@"male",@"score":@"67"},@{@"name":@"Robert Brunne",@"age":@"28",@"sex":@"male",@"score":@"88"}];
/*
1.添加数据姓名:Philip Schiller年龄:29性别:female分数:70到arr数组内。
2.查找数组内"Steve Jobs"的数据并删除。
3.按姓名首字母进行排序。
4.按年龄进行升序排序,如果年龄相同则按性别进行排序。
5.输出成绩大于或等于80分的学员信息。*/
NSMutableArray*newarr3=[NSMutableArray arrayWithArray:arr3];
NSDictionary*dic=[[NSDictionary alloc ]initWithObjectsAndKeys:@"Philip Schiller",@"姓名",@"29",@"年龄",@"female",@"性别",@"70" ,@"分数",nil ];
NSLog(@"输出第一题");
NSLog(@"姓名为%@年龄为%@性别为%@分数为%@",dic[@"姓名"],dic[@"年龄"],dic[@"性别"],dic[@"分数"]);
//NSLog(@"第三题");
// NSSortDescriptor *des=[[NSSortDescriptor alloc]initWithKey:@"name" ascending:YES ];
// NSArray*del=[NSArray arrayWithObjects:des, nil];
// NSArray*sortarr1=[newarr3 sortUsingDescriptors:del];
// NSLog(@"xing ming shu chu ");
// for (id str20 in sortarr1) {
// NSLog(@"姓名为%@年龄为%@性别为%@分数为%@",str20[@"姓名"],str20[@"年龄"],str20[@"性别"],str20[@"分数"]);
//
// }
//第二题
NSMutableArray*ARR=[NSMutableArray arrayWithObject:arr3];
for (int i=0; i<ARR.count; i++) {
if ([ARR[i][@"name"] isEqualToString:@"Steve Jobs"]) {
[ARR removeObject:ARR[i]];
}
}
NSLog(@"删除后");
for (id STR in ARR) {
NSLog(@"姓名是%@年龄为%@性别为%@成绩为%@",STR[@"name"],STR[@"age"],STR[@"sex"],STR[@"score"]);
}
// NSLog(@"第三题");
// NSArray *arrSort=[newarr3 sortedArrayUsingSelector:@selector(compare:)];
// for(id str in arrSort) {
// NSLog(@"姓名为%@年龄为%@性别为%@分数为%@",str[@"name"],str[@"age"],str[@"sex"],str[@"score"]);
// }
//
NSSortDescriptor *des=[[NSSortDescriptor alloc]initWithKey:@"name" ascending:YES ];
NSArray*del=[NSArray arrayWithObjects:des, nil];
NSArray*arrsort4=[newarr3 sortedArrayUsingDescriptors:del];
NSLog(@"第三题");
for (id str20 in arrsort4) {
NSLog(@"姓名为%@年龄为%@性别为%@分数为%@",str20[@"name"],str20[@"age"],str20[@"sex"],str20[@"score"]);
}
NSLog(@"第四题");
NSComparator comp=^(id obj1 ,id obj2){
int age1=[ obj1[@"age"]intValue ];
int age2=[obj2[@"age"]intValue];
if(age1==age2){
return [obj1[@"sex"] compare:obj2[@"sex"]];
}
if(age1<age2){
return NSOrderedAscending;
}else if(age1>age2){
return NSOrderedDescending;
}else{
return NSOrderedSame;
}
};
// NSArray*arrsort2=[newarr3 sortedArrayUsingSelector:@selector(compare:)];
NSSortDescriptor *des1=[[NSSortDescriptor alloc]initWithKey:@"age" ascending:YES ];
NSArray*del1=[NSArray arrayWithObjects:des1, nil];
NSArray*arrsort5=[newarr3 sortedArrayUsingDescriptors:del1];
for ( id one in arrsort5) {
NSLog(@"姓名为%@年龄为%@性别为%@分数为%@",one[@"name"],one[@"age"],one[@"sex"],one[@"score"]);
}
NSLog(@"第五题");
for (id two in newarr3) {
if ( [two [@"score"] intValue]>=80) {
NSLog(@"姓名为%@年龄为%@性别为%@分数为%@",two[@"name"],two[@"age"],two[@"sex"],two[@"score"]);
}
}
}
return 0;
}