OC Assessment Test Questions

Source: Internet
Author: User

#import <Foundation/Foundation.h>

#define NSLOG (FORMAT, ...) printf ("%s\n", [[NSString Stringwithformat:format, # #__VA_ARGS__] utf8string])

int main (int argc, const char * argv[]) {

@autoreleasepool {

/* 1th Please store the following data in a dictionary and output the dictionary content as a string output: "xxx, age xxx, subject xxx, score xxx" (replace XXX with the corresponding data).

*/

NSString *name = @ "Zhang San";

Nsinteger age = 22;

NSNumber *[email protected];

NSString *subject = @ "Mathematics";

Data is stored as a dictionary

Nsdictionary *[email protected]{@ "name": Name,

@ ' age ': @ (age),

@ "Score": Score,

@ "subject": Subject};

NSLog (@ "%@, age%@, subject%@, score%@", dic[@ "name"],dic[@ "ages"],dic[@ "subject"],dic[@ "score"]);

/* Question 2nd: 12,9,34,56,11 into Nsarray array, output: 1) Reverse output 2) descending output */

Nsarray *array=[[nsarray Alloc]initwithobjects:@12,@9,@34,@56,@11,nil];

for (int i=4; I<[array count]; i--) {

NSString *element=[array OBJECTATINDEX:I];

NSLog (@ "%@", Element);

}

NSLog (@ "\ n");

Nscomparator sortblock=^ (ID obj1,id obj2) {

return [Obj2 compare:obj1];

};

Nsarray *sortarray=[array Sortedarrayusingcomparator:sortblock];

for (id str in sortarray) {

NSLog (@ "%@", str);

}

/* Question 3rd to determine if the intermediate directory exists

such as passing strings @ "/home/qianfeng/oc.txt" and @ "Qianfeng"

return: YES

Incoming string @ "/usr/qianfeng/oc.txt and @" Fengqian "

return: NO

*/

NSString *[email protected] "/home/qianfeng/oc.txt";

Nsrange rang=[str rangeofstring:@ "Qianfeng"];

if (rang.location==nsnotfound) {

NSLog (@ "NO");

}else{

NSLog (@ "YES");

}

NSString *[email protected] "/usr/qianfeng/oc.txt";

Nsrange rang1=[str1 rangeofstring:@ "Fengqian"];

if (rang1.location==nsnotfound) {

NSLog (@ "NO");

}else{

NSLog (@ "YES");

}

/* The elements in the array 4th sorted by Chinese

*/

Nsarray *[email protected][@ "Light Rain", @ "Ann", @ "small wind", @ "Rongrong", @ "Zhang Tao" @ "Li Wenrong"];

Nsarray *sortedarr2=[arr2 sortedarrayusingselector: @selector (localizedcompare:)];

For (NSString *str in sortedArr2) {

NSLog (@ "%@", str);

}

}

return 0;

}

OC Assessment Test Questions

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.