#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//1.以下是身份证号,输出身份证人的性别,年龄
NSString *idCard=@"210423198809040427";
//身份证倒数#2位是偶数则为女生
NSString *newId=[idCard substringToIndex:17];
NSString *newAge=[idCard substringToIndex:7];
NSString *str1=@"210423198809040427";
NSRange rang;
rang.location=16;
rang.length=1;
NSString *newStr1=[str1 substringWithRange:rang];
int newSex=[newStr1 intValue];
NSRange rang1;
rang1.location=6;
rang1.length=4;
NSString *newStr2=[str1 substringWithRange:rang1];
int newage=2016-[newStr2 intValue];
if (newSex%2==0) {
NSLog(@"身份证性别:女性 年龄:%d",newage);
}
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 *arr=[dict allKeys];
NSComparator com=^(id obj1,id obj2){
return [obj2 compare:obj1];
};
NSArray *sortArr=[arr sortedArrayUsingComparator:com];
for(NSString *str in sortArr){
NSLog(@"KEY=%@,VALUE=%@",str,dict[str]);
}
//2.将字典的key从Z->A排序,按排序后的key的顺序,输出value,将value按字符串输出
}
return 0;
}