//
Main.m
10.1.2
//
Created by fwzx11 on 16/1/10.
Copyright (c) 2016 Blue Mobi. All rights reserved.
//
#define NSLOG (FORMAT, ...) fprintf (stderr, "%s\n", [[NSString Stringwithformat:format, # #__VA_ARGS__] utf8string]);
#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";
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 *str=[nsstring stringwithformat:@ "%@, age%@ years, subjects%@, score%@", dic[@ "name"],dic[@ "ages"],dic[@ "subject"],dic[@ " Score "];
NSLog (@ "%@", str);
}
NSNumber *[email protected];
NSNumber *[email protected];
NSNumber *[email protected];
NSNumber *[email protected];
NSNumber *[email protected];
Nsarray *brr=[nsarray arraywithobjects:a,b,c,d,e, nil];
NSLog (@ "%@", BRR);
Nscomparator sort1=^ (ID obj1,id obj2)
{//passing in two elements in an array
Nscomparisonresult Result=[obj2 Compare:obj1];
return result; Return a certain value according to your own definition
};
Nsarray *SORT2=[BRR Sortedarrayusingcomparator:sort1]; Sort by return value
For (ID str2 in sort2)
{
NSLog (@ "%@", str2);
}
NSLog (@ "\ n");
Nsarray *sort3=[brr Sortedarrayusingselector: @selector (Class)]; Sort by return value
For (ID str2 in SORT3)
{
NSLog (@ "%@", str2);
}
2nd question: 12,9,34,56,11 deposit Nsarray Array, output: 1) Reverse output 2) descending output
Nsarray *[email protected][@12,@9,@34,@56,@11];
For (Nsinteger i=[arr1 count]-1;i>=0;i--) {
NSLog (@ "%@", Arr1[i]);
}
Nscomparator comp=^ (ID obj1,id obj2) {
Nscomparisonresult Result=[obj2 Compare:obj1];
return result;
};
Nsarray *sortedarr=[arr1 Sortedarrayusingcomparator:comp];
For (ID i in Sortedarr) {
NSLog (@ "%@", 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 rang1=[str rangeofstring:@ "Qianfeng"];
if (rang1.location==nsnotfound) {
NSLog (@ "not found");
}
else{
NSLog (@ "found at Loacation:%ld", rang1.location);
}
Nsrange rang2=[str rangeofstring:@ "Fengqian"];
if (rang2.location==nsnotfound) {
NSLog (@ "not found");
}
else{
NSLog (@ "found at Loacation:%ld", rang2.location);
}
/* The elements in the array 4th sorted by Chinese
*/
Nsarray *[email protected][@ "Light Rain", @ "Ann", @ "small wind", @ "Rongrong", @ "Zhang Tao" @ "Li Wenrong"];
Nsarray *sortedarr2=[arr sortedarrayusingselector: @selector (localizedcompare:)];
For (NSString *str in sortedArr2) {
NSLog (@ "%@", str);
}
return 0;
}
About dictionaries and arrays of flashbacks, custom sorting, intermediate catalogs, Chinese sorting