@maximsemin23

Как сделать аналогичную программу на c++ (для тех кто знает python и c++)?

Код на python:
spoiler
def divide(a, b):
    return int(a) / int(b)

def fold(a, b):
    return int(a) + int(b)

def multiple(a, b):
    return int(a) * int(b)

def take(a, b):
    return int(a) - int(b)

def main():
    print('Введите выражение')
    userInput = input()
    while True:
        userInput2 = userInput.split('/')
        l = len(userInput2)
        if l > 1:
            result = divide(userInput2[0], userInput2[1])
            print(result)
            break
        
        userInput2 = userInput.split('+')
        l = len(userInput2)
        if l > 1:
            result = fold(userInput2[0], userInput2[1])
            print(result)
            break

        userInput2 = userInput.split('*')
        l = len(userInput2)
        if l > 1:
            result = multiple(userInput2[0], userInput2[1])
            print(result)
            break

        userInput2 = userInput.split('-')
        l = len(userInput2)
        if l > 1:
            result = take(userInput2[0], userInput2[1])
            print(result)
            break

        

main()

Фактически я знаю все, кроме .split, так что мне хотелось бы чтобы вы привели пример работы с аналогом .split в c++
  • Вопрос задан
  • 142 просмотра
Пригласить эксперта
Ответы на вопрос 1
sergey-gornostaev
@sergey-gornostaev Куратор тега Python
Седой и строгий
Фактически я знаю все, кроме .split, так что мне хотелось бы чтобы вы привели пример работы с аналогом .split в c++

Пробовали в Google вбить запрос "c++ split string"?
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы