Câu hỏi phỏng vấn Objective-C
Câu hỏi

A grandparent, parent and child problem

Câu trả lời

Here is a possible solution to the "Grandparent, Parent and Child" problem in Objective-C:

Grandparent, Parent and Child Problem

The problem is as follows:

  • There is a grandparent, parent and child
  • The grandparent has a certain amount of money
  • The grandparent gives half of their money to the parent
  • The parent gives half of their money to the child
  • The child spends all their money on candy
  • The grandparent is left with a certain amount of money
  • What is the amount of money the grandparent is left with?

Solution in Objective-C

Here is a possible solution in Objective-C:

objc Copy
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // Initial amount of money the grandparent has
        int grandparentMoney = 100;
        
        // Grandparent gives half to parent
        int parentMoney = grandparentMoney / 2;
        grandparentMoney = grandparentMoney - parentMoney;
        
        // Parent gives half to child
        int childMoney = parentMoney / 2;
        parentMoney = parentMoney - childMoney;
        
        // Child spen...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

Explain method swizzling. When you would use it?

middle

What are some limitations and problems you can face with categories?

junior

What is the difference between copy and retain ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào