#import <Foundation/Foundation.h>
int Main (int argc, const Char * argv[]) {
@autoreleasepool {
//1. The following is the ID number, the gender of the output ID, age
nsstring *idcard=@ "210423198809040427";
NSLog(@ " identity card %@", Idcard);
nsrange NL;
NL. location=6;
NL. length=4;
nsstring *year=[idcard substringwithrange: NL];
int yearnum=[year intvalue];
int age=-yearnum;
NSLog(@ " age is %d", ages);
// ID card Countdown #2 digits is an even number for girls
nsrange xb;
Xb. location=+;
Xb. length=1;
nsstring *gender=[idcard substringwithrange: XB];
int gendernum=[gender intvalue];
int sex=gendernum% 2;
if (sex==0) {
NSLog(@ " female ");
}Else{
NSLog(@ " female ");
}
//2. sort the key of the dictionary from z->a , output value in the order of the sorted key, output value as a string
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;
}
iOS exercises--seventh issue