今天开始进入狂暴状态,开启疯狂面具

 

1.objective-c中的数字对象都有哪些,简述它们与基本数据类型的区别是什么?

数字对象是 NSNumber

基本数据类型为 fload double char long int .它们都不是对象,不能向它们发送消息,

不能将这些基本数据类型,直接存储到NSArray里面,可以使用NSNumber 类根据这些数据类型来创建对象。

搜索了一下,发现,数字对象,除了我提到的那个以外,还有NSValue,NSNull

对于,NSNumber比较熟悉,NSValue和NSNull我用的比较少。

先说说,NSNull,因为在NSArray和 NSDictionary 中nil有特殊含义(表示列表结束),所以不能在集合中放入nil值,如果确实需要存储一个表示“什么都没有”的值,可以使用NSNull类,只有一个方法

+(NSNull *)null;

例如

[contact setObject:[NSNull null] forey:@"home fax"]

访问如下:

id homefax;

homefax=[contact objectForKey:@"home fax"];

if(homefax=[NSNull null])

{

//..............................

}

 

///

NSNumber 是NSValue 的子类,NSValue 可以包装任何值

...................................此处省略一万字

//    NSMutableArray *mutableArray=[[NSMutableArray alloc] init];

//    CGRect rect=CGRectMake(1, 2, 2, 3);

//    NSValue *rectValue=[NSValue valueWithBytes:&rect objCType:@encode(CGRect)];

//    [mutableArray addObject:rectValue];

//    NSValue *rectValueFromArray=[mutableArray objectAtIndex:0];

//    CGRect rectFromArray;

//    [rectValueFromArray getValue:&rectFromArray];


 CGRect rect=CGRectMake(1, 2, 2, 3);

    NSValue *value=[NSValue valueWithCGRect:rect];

    CGRect rectAfter;

    [value getValue:&rectAfter];


2.nslog 函数输出一个浮点类型,结果四舍五入,保留一位小数。

 

    float f=123.355;

    NSLog(@"%.1f",f);

    //加0.5,取整,呵呵,又忘了这个算法了

    float afterfloat=round(f*10+0.5)/10;

    NSLog(@"%f",afterfloat);


    NSLog(@"%0.20f", 1.345); // output 1.34**

    NSLog(@"%0.2f", 1.345); // output 1.34**

    NSLog(@"%0.20f", 1.3451);// output 1.35

    NSLog(@"%0.2f", 1.3451);// output 1.35

    NSLog(@"%0.2f", round(1.345 * 100)/100.);//output 1.35

不要忘了加0.5,取整    http://www.cocoachina.com/bbs/simple/?t46794.html

里面还有个有意思的现象:http://stackoverflow.com/questions/12122092/why-this-output-nslog0-2f-1-345-output-1-34


  //3

//    NSString *string=@"20|http:";

//    NSRange range=[string rangeOfString:@"|"];

//    NSString *front=[string substringToIndex:range.location];

//    NSString *after=[string substringFromIndex:range.location+1];

//    NSLog(@"front:%@,after:%@",front,after);



 

//4

    //NSDictionary

//    NSMutableDictionary

//    NSMutableDictionary *mutableDictionary=[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"object1",@"key1",@"object2",@"key2", nil];

//    NSLog(@"Before Add:%@",mutableDictionary);

//    [mutableDictionary setObject:@"object3" forKey:@"key3"];

//    NSLog(@"Before Delete:%@",mutableDictionary);

//    [mutableDictionary removeObjectForKey:@"key3"];

//    NSLog(@"After Delete:%@",mutableDictionary);

//    NSLog(@"%@",[mutableDictionary objectForKey:@"key1"]);


5.

其实

    NSString *path=[[NSBundle mainBundle] pathForResource:@"" ofType:@""];

//    

//    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);

//    //(lldb) po documentationpath

//    //(NSString *) $4 = 0x0835c370 /Users/CompanyName/Library/Application Support/iPhone Simulator/6.0/Applications/66EBAED0-858D-424B-A78E-896E3B0AFECB/Library/Documentation

//    NSString *documentationpath=[paths objectAtIndex:0];

//

//    NSFileManager *fileManager=[[NSFileManager alloc] init];

//    NSString *destinationPath=[NSString stringWithFormat:@"%@/UserData",documentationpath];

//    if ([fileManager fileExistsAtPath:destinationPath]) {

//        [fileManager createDirectoryAtPath:destinationPath withIntermediateDirectories:false attributes:nil error:nil];

//    }


6.调用self.name的时候,执行的是name属性的set方法,调用name的时候,直接给对象的实例变量赋值。



    int a=5;

    int b;

    b=SQUAKE(a++);

    

//    a=7;b=30

    a=5;

    b=SQUAKE(++a);

    //42






7,定义属性时,什么时候用copy,resign,retain?

12.声明一个静态方法和一个实例方法。

13.写一个发送同步http请求,并返回结果的方法

14.怎样启动一个新县城,子线程怎样刷新主UI

15.什么是MVC,你工作时怎样运用它。


2.进程间通信的方式有——

3.链表逆序(链表交叉)

4.c 语言中讲讲static 变量和 static 函数有什么作用


1.static 全局变量 与 普通变量;局部变量 普通变量;static 函数  和普通函数。

#define Per_YEAR (365*24*60*60)UL 后面这个干嘛的

4.写一个委托

5.写一个NSString 类的实现。


8.关键字const 有什么含义?

9.static 关键字的作用 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个问题可以通过动态规划来解决。我们可以使用一个二维数组dp,其中dp[i][j]表示前i块狂暴石中,总愤怒值和总暴躁值相差为j的最小愤怒值。 首先,我们需要计算出所有狂暴石的愤怒值之积和总暴躁值。然后,我们可以初始化dp数组,将所有元素初始化为无穷大,除了dp[0][0]初始化为0。 接下来,我们可以使用两个循环来填充dp数组。外层循环遍历狂暴石的数量i,内层循环遍历总愤怒值和总暴躁值的差值j。在每次迭代中,我们可以选择将第i块狂暴石放入或不放入选取的集合中。 如果选择放入第i块狂暴石,那么dp[i][j]的值可以通过dp[i-1][j-狂暴石i的暴躁值] + 狂暴石i的愤怒值来更新。如果选择不放入第i块狂暴石,那么dp[i][j]的值可以通过dp[i-1][j]来更新。 最后,我们可以遍历dp[n][j],找到使得总愤怒值和总暴躁值相差最小的j值,即为所求的答案。 以下是一个使用动态规划解决该问题的C++代码示例: ```cpp #include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int n; cin >> n; vector<int> anger(n); vector<int> irritability(n); int totalAnger = 1; int totalIrritability = 0; for (int i = 0; i < n; i++) { cin >> anger[i]; totalAnger *= anger[i]; } for (int i = 0; i < n; i++) { cin >> irritability[i]; totalIrritability += irritability[i]; } int diff = abs(totalAnger - totalIrritability); vector<vector<int>> dp(n + 1, vector<int>(diff + 1, INT_MAX)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= diff; j++) { if (j >= irritability[i-1]) dp[i][j] = min(dp[i-1][j], dp[i-1][j-irritability[i-1]] + anger[i-1]); else dp[i][j] = dp[i-1][j]; } } int minAngerDiff = INT_MAX; for (int j = 0; j <= diff; j++) { minAngerDiff = min(minAngerDiff, abs(diff - 2 * dp[n][j])); } cout << minAngerDiff << endl; return 0; } ``` 希望这个解决方案可以帮助到你!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值