#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//1.以下是身份证号,输出身份证人的性别,名字
// NSString *idCard=@210423198809040427;
//身份证倒数#2位是偶数则为女生
NSString *idCard=@"210423198809040427";
NSRange strc=NSMakeRange(16, 1);
NSRange stcr1=NSMakeRange(6, 4);
NSString *sing=[idCard substringWithRange:strc];
NSString *sing1=[idCard substringWithRange:stcr1];
int ste=[sing intValue];
int ste1=[sing1 intValue];
if (ste%2==0) {
NSLog(@"女 年龄:%d",2016-ste1);
}else{
NSLog(@"男 年龄:%d",2016-ste1);
}
//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",
};
NSDictionary *idc=[NSDictionary dictionaryWithDictionary:dict];
NSArray *str1=[idc allKeys];
str1=[str1 sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj2 compare:obj1];
}];
for (id str in str1) {
NSLog(@"%@",str);
}
NSMutableArray *arr1=[[NSMutableArray alloc]init];
for(id ser in str1){
[arr1 addObject:[dict objectForKey:ser]];
}
NSLog(@"%@",arr1);
NSString *Array=[arr1 componentsJoinedByString:@""];
NSLog(@"%@",Array);
}
return 0;
}