• OC练习题


    #import <Foundation/Foundation.h>

    int main(int argc, const char * argv[]) {

        @autoreleasepool {

            NSArray *arr=@[@{@"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数组内。

            NSMutableArray *newarr=[NSMutableArray arrayWithArray:arr];

            [newarr addObject:@{@"name":@"Philip Schiller",@"age":@"29",@"sex":@"female",@"score":@"70"}];

            for(id str in newarr){

                  NSLog(@"%@",str);

            }

            

             //2.查找数组内"Steve Jobs"的数据并删除。

            NSMutableArray *muarr=[NSMutableArray array];

            for (int i=0; i<newarr.count; i++) {

                NSDictionary *dic1=newarr[i];

                if ( ![dic1[@"name"] isEqual:@"Steve Jobs"]) {

                    [muarr addObject:dic1];

                }

            }

            for (NSDictionary *dic in muarr) {

                NSLog(@"姓名:%@,年龄:%@",dic[@"name"],dic[@"age"]);

            }

             //3.按姓名首字母进行排序。

            NSSortDescriptor *nameWithSort=[[NSSortDescriptor alloc]initWithKey:@"name" ascending:YES];

            NSArray *elementarr=[NSArray arrayWithObject:nameWithSort];

            NSArray *sortArray=[arr sortedArrayUsingDescriptors:elementarr];

            for (NSDictionary *dic in muarr) {

                NSLog(@"姓名:%@",dic[@"name"]);

            }

            NSLog(@" ");

             //4.按年龄进行升序排序,如果年龄相同则按性别进行排序。

            NSSortDescriptor *ageWithSort=[[NSSortDescriptor alloc]initWithKey:@"age" ascending:1];

            NSSortDescriptor *sexWithSort=[[NSSortDescriptor alloc]initWithKey:@"sex" ascending:1];

            NSArray *newgood=[muarr sortedArrayUsingDescriptors:[NSArray arrayWithObjects:ageWithSort,sexWithSort, nil]];

           for (NSDictionary *dic1 in newgood) {

               NSLog(@"姓名:%@ %@",dic1[@"name"],dic1[@"sex"]);

            }

             //5.输出成绩大于或等于80分的学员信息。

            for (NSDictionary *dict in newgood) {

                

                int b=[dict[@"score"] intValue];

                if(b>80){

                    NSLog(@"姓名:%@,年龄:%@,性别%@,分数:%@",dict[@"name"],dict[@"age"],dict[@"sex"],dict[@"score"]);

                }

            }

        }

        return 0;

    }

  • 相关阅读:
    wiki iso88591字符表的解释
    [c]字符1一维数组求长度
    vim 用户配置
    PHP中向浏览器输出图片
    如何及时取消 BackgroundWorker 组件的后台工作
    python basic
    php5.1中的时区设置。
    MyBatis的深入原理分析之1架构设计以及实例分析
    hibernate缓存:一级缓存和二级缓存
    Spring 注解(Annotation)代替XML实现零配置
  • 原文地址:https://www.cnblogs.com/jidezhi/p/5121738.html
Copyright © 2020-2023  润新知