#import <Foundation/Foundation.h>
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";
Nsdictionary *[email protected]{@ "name": Name,
@ ' age ': @ (age),
@ "Score": Score,
@ "Subject": Subject
};
NSString *str1=[nsstring stringwithformat:@ "%@ age%@ account%@ score%@", dic[@ "name"],dic[@ "ages"],dic[@ "score"],dic[@ "subject "]];
NSLog (@ "%@", str1);
NSLog (@ "%@ age%@ account%@ score%@", dic[@ "name"],dic[@ "ages"],dic[@ "score"],dic[@ "subject"]);
/* Question 2nd: 12,9,34,56,11 into Nsarray array, output: 1) Reverse output 2) descending output */
Nsmutablearray *arr=[@[@12,@9,@34,@56,@11]mutablecopy];
Nsarray *arr1=[arr sortedarrayusingcomparator:^nscomparisonresult (ID obj1, id obj2) {
return [Obj2 compare:obj1];
}];
NSLog (@ "descending output");
For (ID ste in Arr1) {
NSLog (@ "%@", Ste);
}
NSLog (@ "reverse");
for (int i = 0; i<arr.count/2; i++) {
[Arr exchangeobjectatindex:i withobjectatindex:arr.count-1-i];
}
NSLog (@ "%@", ARR);
Reverse Method Two
Nsarray *[email protected][@12,@9,@34,@56,@11];
For (Nsinteger I=[arr3 count]-1;i>=0;i--) {
NSLog (@ "%@", Arr3[i]);
}
/* 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 ran=[string rangeofstring:@ "Qianfeng"];
if (ran.location==nsnotfound) {
NSLog (@ "NO");
}else{nslog (@ "YES");}
NSString *[email protected] "/usr/qianfeng/oc.txt";
Nsrange rang1=[str rangeofstring:@ "Fengqian"];
if (rang1.location==nsnotfound) {
NSLog (@ "NO");
}
else{
NSLog (@ "YES");
}
4th the elements in the array are sorted by Chinese
Nsarray *[email protected][@ "Light Rain", @ "Ann", @ "small wind", @ "Rongrong", @ "Zhang Tao" @ "Li Wenrong"];
Nsarray *arrr=[arr sortedarrayusingselector: @selector (localizedstandardcompare:)];
For (ID ser in arrr) {
NSLog (@ "%@", Ser);
}
}
return 0;
}
Practice string is stored in the dictionary array in descending order the string directory does not exist in the array Chinese sort