// // main.m // 之前1 // // Created by syrcfwzx on 16/1/11. // Copyright (c) 2016年 syrcfwzx. All rights reserved. // #import <Foundation/Foundation.h> #define NSLog(FORMAT, ...) printf("%s ", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]) int main(int argc, const char * argv[]) { @autoreleasepool { /* 第1题 请将如下数据存储成字典,并将字典内容以字符串形式输出,输出:"XXX,年龄XXX岁,科目XXX,分数XXX"(将XXX替换为相应的数据)。 */ NSString *name = @"张三"; NSInteger age = 22; NSNumber *score=@88.7; NSString *subject = @"数学"; NSDictionary *dic = @{@"name":name, @"age":@(age), @"score":score, @"subject":subject }; NSLog(@"%@ %@ %@ %@",dic[@"name"],dic[@"age"],dic[@"score"],dic[@"subject"]); /*第2题:12,9,34,56,11存入NSArray数组,输出结果:1)倒序输出2)降序输出*/ NSArray *array = [NSArray arrayWithObjects:@12,@9,@34,@56,@11, nil]; NSArray *arr = [array sortedArrayUsingComparator:^NSComparisonResult(id obj2, id obj1) { return [obj1 compare:obj2]; }]; NSLog(@"%@",arr); NSArray *arr2 = [array sortedArrayUsingSelector:@selector(class)]; NSLog(@"%@",arr2); // 第4题数组内元素按中文排序 // NSArray *arr=@[@"小雨",@"安安",@"小风",@"荣荣",@"张涛",@"李文荣"]; // NSArray *arrr=[arr sortedArrayUsingSelector:@selector(localizedStandardCompare:)]; // for(id ser in arrr){ // NSLog(@"%@",ser); // } NSArray *arr5=@[@"小雨",@"安安",@"小风",@"荣荣",@"张涛",@"李文荣"]; NSArray *sortArr = [arr5 sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { return [obj1 localizedCompare:obj2]; }]; for(id obj in sortArr) { NSLog(@"%@",obj); } } return 0; }