标签:
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 = @"数学";
NSLog(@"第一题");
NSString *name = @"张三";
NSInteger age = 22;
NSNumber *score=@88.7;
NSString *subject = @"数学";
NSDictionary *dic=@{@"name":name,
@"age":@(age),
@"score":score,
@"subject":subject};
NSString *str=[NSString stringWithFormat:@"%@,年龄%@岁,科目%@,分数%@",dic[@"name"],dic[@"age"],dic[@"subject"],dic[@"score"]];
NSLog(@"%@",str);
}
NSNumber *a=@12;
NSNumber *b=@9;
NSNumber *c=@34;
NSNumber *d=@56;
NSNumber *e=@11;
NSArray *brr=[NSArray arrayWithObjects:a,b,c,d,e, nil];
NSLog(@"第二题");
//第2题:12,9,34,56,11存入NSArray数组,输出结果:1)倒序输出2)降序输出
NSLog(@"倒序输出方法一");
NSArray *arr1=@[@12,@9,@34,@56,@11];
for (NSInteger i=[arr1 count]-1;i>=0;i--){
NSLog(@"%@",arr1[i]);
}
NSLog(@"倒序输出方法二");
NSArray* reversedArray=[[brr reverseObjectEnumerator]allObjects];
for(id str2 in reversedArray)
{
NSLog(@"%@",str2);
}
NSLog(@"降序排序");
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);
}
NSLog(@"第3题 判断中间目录是否存在");
/* 第3题 判断中间目录是否存在
比如 传入字符串 @"/home/qianfeng/oc.txt" 和 @"qianfeng"
返回:YES
传入字符串 @"/usr/qianfeng/oc.txt 和 @"fengqian"
返回:NO
*/
NSString *str=@"/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);
}
NSLog(@"第4题数组内元素按中文排序");
/* 第4题数组内元素按中文排序
*/
NSArray *arr=@[@"小雨",@"安安",@"小风",@"荣荣",@"张涛",@"李文荣"];
NSArray *sortedArr2=[arr sortedArrayUsingSelector:@selector(localizedCompare:)];
for (NSString *str in sortedArr2) {
NSLog(@"%@",str);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/wuduo/p/5120705.html