码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 7

时间:2016-01-08 18:42:14      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
    //1.以下是身份证号,输出身份证人的性别,年龄
        NSString *idCard=@"210423198809040427";
        
        NSString* str =[NSString stringWithFormat:@"%@",idCard];
       
        NSRange range = NSMakeRange(16, 1);
        NSRange range1 = NSMakeRange(6, 4);
        NSString* str1 = [str substringWithRange:range];
        NSString* str2 =[str substringWithRange:range1];
        int a =[str1 intValue];
        int b =[str2 intValue];
        if(a%2==0)
        {
            NSLog(@"性别女 年龄%d",2016-b);
        }
        else
        {
            NSLog(@"性别男 年龄%d",2016-b);
        }
        
               //身份证倒数#2位是偶数则为女生
    //2.将字典的key从Z->A排序,按排序后的key的顺序,输出value,将value按字符串输出
        NSDictionary *dict=@{@"R":@"e",
                             @"T":@"e",
                             @"D":@"b",
                             @"S":@"u",
                             @"K":@"a",
                             @"A":@"s",
                             @"O":@" ",
                             @"N":@"p",
                             @"B":@"b",
                             @"J":@"u",
                             @"F":@" ",
                             @"U":@"t",
                             @"H":@"l",
                             @"E":@"j",
                             @"Z":@"s",
                             
                             };
        NSArray* array = [dict allKeys];
        NSComparator sortBlock =^(id obj1,id obj2)
        {
            return [obj2 compare:obj1];
        };
        NSArray* sortArr =[array sortedArrayUsingComparator:sortBlock];
        for(id obj in sortArr)
        {
            NSLog(@"%@:%@",obj,[dict objectForKey:obj]);
        }
        
        NSMutableArray* m =[[NSMutableArray alloc]init];
        for(id ob in sortArr)
        {
            [m addObject:[dict objectForKey:ob]];
        }
        NSLog(@"%@",m);

        NSString* join = [m componentsJoinedByString:@""];
        NSLog(@"%@",join);
    }
    
    return 0;
}

 

iOS 7

标签:

原文地址:http://www.cnblogs.com/hezhuangzhuang/p/5114026.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!