• 中文排序


    #import <Foundation/Foundation.h>
    #define NSLog(FORMAT, ...) printf("%s
    ", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            /* 第1题 请将如下数据存储成字典,并将字典内容以字符串形式输出,输出:"XXX,年龄XXX岁,科目XXX,分数XXX"(将XXX替换为相应的数据)。
             */
            NSString *name = @"张三";
            NSInteger age = 22;
            NSNumber  *score=@88.7;
            NSString *subject = @"数学";
            NSDictionary *dic=@{@"name":name,
                                @"age":@(age),
                                @"score":score,
                                @"subject":subject
                                };
            NSString *str1=[NSString stringWithFormat:@"%@ 年龄%@ 科目%@ 分数%@",dic[@"name"],dic[@"age"],dic[@"score"],dic[@"subject"]];
            NSLog(@"%@",str1);
            NSLog(@"%@ 年龄%@ 科目%@ 分数%@",dic[@"name"],dic[@"age"],dic[@"score"],dic[@"subject"]);
                    /*第2题:12,9,34,56,11存入NSArray数组,输出结果:1)倒序输出2)降序输出*/
            NSMutableArray *Arr=[@[@12,@9,@34,@56,@11]mutableCopy];
            NSArray *Arr1=[Arr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
                return [obj2 compare:obj1];
            }];
            NSLog(@"降序输出");
            for(id ste in Arr1){
            
                NSLog(@"%@",ste);
            }
            NSLog(@"倒序");
            for (int i = 0; i<Arr.count/2; i++) {
                [Arr exchangeObjectAtIndex:i withObjectAtIndex:Arr.count-1-i];
            }
            NSLog(@"%@",Arr);
            //倒序法二
            NSArray *arr3=@[@12,@9,@34,@56,@11];
            for (NSInteger i=[arr3 count]-1;i>=0;i--){
                NSLog(@"%@",arr3[i]);
            }
                            /* 第3题 判断中间目录是否存在
                     比如 传入字符串 @"/home/qianfeng/oc.txt" 和 @"qianfeng"
                     返回:YES
                     传入字符串 @"/usr/qianfeng/oc.txt 和 @"fengqian"
                     返回:NO
                     */
            NSString *string=@"/home/qianfeng/oc.txt";
            NSRange ran=[string rangeOfString:@"qianfeng"];
            if (ran.location==NSNotFound) {
                NSLog(@"NO");
            }else{NSLog(@"YES");}
            NSString *str=@"/usr/qianfeng/oc.txt";
            NSRange rang1=[str rangeOfString:@"fengqian"];
            if(rang1.location==NSNotFound){
                NSLog(@"NO");
            }
            else{
                NSLog(@"YES");
            }
         // 第4题数组内元素按中文排序
         //           NSArray *arr=@[@"小雨",@"安安",@"小风",@"荣荣",@"张涛",@"李文荣"];
    //        NSArray *arrr=[arr sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
    //        for(id ser in arrr){
    //            NSLog(@"%@",ser);
    //        }
            NSArray *arr5=@[@"小雨",@"安安",@"小风",@"荣荣",@"张涛",@"李文荣"];
            NSArray *sortArr = [arr5 sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
                return [obj1 localizedStandardCompare:obj2];
            }];
            for(id obj in sortArr)
            {
                NSLog(@"%@",obj);
            }
        }
        return 0;
    }
  • 相关阅读:
    [PHP]解决PHP Call to undefined function ldap_connect()
    [Nginx] Nginx配置PHP应用传递PATH_INFO变量
    [PHP]解决PHP Fatal error: Call to undefined function mcrypt_get_iv_size()
    [CentOS] centos下安装最新稳定版nginx
    [CentOS]查看centos的发行版本情况
    [MySQL]创建用户并指定某一数据库权限
    [PHP] 安装memcached扩展
    [http]301和302的区别
    [javascript] 报错SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
    [GO项目]开源免费在线客服系统-真正免费开源-GOFLY0.3.5发布-极简强大Go语言开发WEB网页客服
  • 原文地址:https://www.cnblogs.com/hezhuangzhuang/p/5121023.html
Copyright © 2020-2023  润新知