Как перевернуть строку с помощью рекурсии? [закрыто]

Масштабирование по фиксированному значению не является хорошей идеей ... поскольку я уверен, что любой, кто использовал принятый ответ, вероятно, узнал, когда вышел iPhone 5.

Вот фрагмент кода для динамического масштабирования на основе разрешения экрана, чтобы исключить буквенный бокс.

// Device's screen size (ignoring rotation intentionally):
CGSize screenSize = [[UIScreen mainScreen] bounds].size;

// iOS is going to calculate a size which constrains the 4:3 aspect ratio
// to the screen size. We're basically mimicking that here to determine
// what size the system will likely display the image at on screen.
// NOTE: screenSize.width may seem odd in this calculation - but, remember,
// the devices only take 4:3 images when they are oriented *sideways*.
float cameraAspectRatio = 4.0 / 3.0;
float imageWidth = floorf(screenSize.width * cameraAspectRatio);
float scale = ceilf((screenSize.height / imageWidth) * 10.0) / 10.0;

self.ipc.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
-7
задан ki ng 19 March 2019 в 07:00
поделиться

1 ответ

Если вы хотите использовать рекурсивный метод, зачем использовать в нем цикл ...?

У меня есть простой метод, который возвращает обратную строку, используя рекурсию.

public string ReverseString(string s)
    {
        if (s == null || s.Length <= 1)  // if length is less or equal 1 then also returns
            return s;

        return ReverseString(s.Substring(1)) + s[0];
    }

Пример вывода прилагается: enter image description here

0
ответ дан Hammad Sajid 19 March 2019 в 07:00
поделиться
Другие вопросы по тегам:

Похожие вопросы: