#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//1.以下是身份证号,输出身份证人的性别,年龄
NSString *idCard=@"210423198809040427";
NSLog(@"身份证%@",idCard);
NSRange NL;
NL.location=6;
NL.length=4;
NSString *year=[idCard substringWithRange:NL];
int yearnum=[year intValue];
int age=2016-yearnum;
NSLog(@"年龄为%d",age);
//身份证倒数#2位是偶数则为女生
NSRange xb;
xb.location=16;
xb.length=1;
NSString *gender=[idCard substringWithRange:xb];
int gendernum=[gender intValue];
int sex=gendernum % 2;
if (sex==0) {
NSLog(@"女");
}else{
NSLog(@"女");
}
//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 *zimu=[dict allKeys];
NSComparator sortBlock =^(id obj1,id obj2)
{
return [obj2 compare:obj1];
};
NSArray* sortArr =[zimu sortedArrayUsingComparator:sortBlock];
NSMutableArray* m =[[NSMutableArray alloc]init];
for(id ob in sortArr)
{
[m addObject:[dict objectForKey:ob]];
}
NSString* join = [m componentsJoinedByString:@""];
NSLog(@"%@",join);
}
return 0;
}