字符串作业题目以及答案1
2013-03-19 17:52
267 查看
1.现有如下定义的字符串: NSMutableString * str=@“iphoneAndroid”,能不能对该字符串进行修改,如果能,请输出删除Android后的新字符串。 2求字符串“158”和“39”按十进制数值做差后的结果以字符串形式输出 3取出符串“123-456-789-000”中的数字部分,组成一个新的字符串输出,(提示:可变字符串;返回数组) 4放四个十进制三位数到一个数组中,然后按从小到大排序后组成一个新的数组
答案:
#import "KAppDelegate.h"
@implementation KAppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]] autorelease];
//1
NSMutableString *str = [[NSMutableStringalloc] initWithString:@"iphoneAndroid"];
NSRange r1 = {6,7};
NSRange r2 = NSMakeRange(6, 7);
[str deleteCharactersInRange:r2];
NSLog(@"str = %@",str);
[str release];
//2
int a = 158;
int b = 39;
int c = a - b;
NSString *str1 = [NSString stringWithFormat:@"%d",c];
NSLog(@"str1 = %@",str1);
//3
NSString *str2 = @"123-456-789-000";
NSArray *arr = [str2 componentsSeparatedByString:@"-"];
NSLog(@"arr = %@",arr);
NSString *str3=[arr componentsJoinedByString:@""];
NSLog(@"str3 = %@",str3);
//4
NSMutableArray *arr2 = [NSMutableArrayarrayWithObjects:@"901",@"675",@"110",@"123",nil];
//NSArray *ar = @[@"123",@"345"];//只支持6.0以上的系统
for (int i = 0; i<arr2.count - 1; i++)
{
for (int j = 0; j < arr2.count - i - 1; j++)
{
NSString *p = [arr2 objectAtIndex:j];
NSString *q = [arr2 objectAtIndex:j+1];
if ([p intValue] > [q intValue])
{
//[arr2 exchangeObjectAtIndex:j+1 withObjectAtIndex:j];//只支持6.0以上的系统
NSString *tmp = arr2[j];
arr2[j] = arr2[j+1];
arr2[j+1] = tmp;
}
}
}
NSLog(@"arr2 = %@",arr2);
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
returnYES;
}
答案:
#import "KAppDelegate.h"
@implementation KAppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]] autorelease];
//1
NSMutableString *str = [[NSMutableStringalloc] initWithString:@"iphoneAndroid"];
NSRange r1 = {6,7};
NSRange r2 = NSMakeRange(6, 7);
[str deleteCharactersInRange:r2];
NSLog(@"str = %@",str);
[str release];
//2
int a = 158;
int b = 39;
int c = a - b;
NSString *str1 = [NSString stringWithFormat:@"%d",c];
NSLog(@"str1 = %@",str1);
//3
NSString *str2 = @"123-456-789-000";
NSArray *arr = [str2 componentsSeparatedByString:@"-"];
NSLog(@"arr = %@",arr);
NSString *str3=[arr componentsJoinedByString:@""];
NSLog(@"str3 = %@",str3);
//4
NSMutableArray *arr2 = [NSMutableArrayarrayWithObjects:@"901",@"675",@"110",@"123",nil];
//NSArray *ar = @[@"123",@"345"];//只支持6.0以上的系统
for (int i = 0; i<arr2.count - 1; i++)
{
for (int j = 0; j < arr2.count - i - 1; j++)
{
NSString *p = [arr2 objectAtIndex:j];
NSString *q = [arr2 objectAtIndex:j+1];
if ([p intValue] > [q intValue])
{
//[arr2 exchangeObjectAtIndex:j+1 withObjectAtIndex:j];//只支持6.0以上的系统
NSString *tmp = arr2[j];
arr2[j] = arr2[j+1];
arr2[j+1] = tmp;
}
}
}
NSLog(@"arr2 = %@",arr2);
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
returnYES;
}
相关文章推荐
- 通知监听作业题目以及答案2
- 一些C语言期末作业 题目以及自己做的答案。
- RHCE题目以及答案1
- JAVA--第十周作业编写之一个Teacher类负责给出算术题目,随机给出两个整数并进行运算,并判断回答者的答案是否正确;编写一个GUI类ComputerFrame,回答者可以通过GUI看到题目并给出
- (1.4.8)2013-4-13腾讯实习生招聘笔试题目以及答案
- SpringMVC 面试题目以及答案
- 前端工程师面试题目以及答案
- UFT基础_16作业讲解-切割字符串以及字典重构excel
- c语言常见50题 及答案(递归 循环 以及常见题目)
- 与oc字符串有关的习题以及答案
- 2013第四届蓝桥杯决赛Java高职高专组题目以及解法答案
- 我的第一次数据库作业:题目原文及部分答案
- c语言常见50题 及答案(递归 循环 以及常见题目)
- 深圳c#面试第三天 题目以及答案
- [11]PHP_W3Cschool中的PHP测试题题目以及答案
- 题目1029:魔咒词典(map使用以及字符串读取函数总结)
- 数据库题目以及答案
- 题目1103:二次方程计算器(字符串操作以及基础数学知识)
- 第一个python作业题目以及代码
- strcat、strcpy、strcmp的实现,以及有关字符串处理需要注意的地方