iOS exercises--seventh issue

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.