#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