Существует ли удобная функция в цели-c / касание какао для нахождения самого низкого количества?

Я положил свои объяснения в код ниже

from datetime import datetime  # yes they named a class the same as module
x = '''2014.16020 2019.07190
2000.05750 2019.10750
2001.82610 2019.10750
2010.36280 2019.07190
2005.24570 2019.10750
2015.92610 2019.10750
2003.43600 2014.37100'''

# split input into lines. Assumption here is that there is one pair of dates per each line
lines = x.splitlines() 
# set up a container (list) for outputs
deltas = []
# process line by line
for line in lines:
    # split line into separate dates
    inputs = line.split()
    dates = []
    for input in inputs:
        # convert text to number
        date_decimal = float(input)
        # year is the integer part of the input
        date_year = int(date_decimal)
        # number of days is part of the year, which is left after we subtract year
        year_fraction = date_decimal - date_year
        # a little oversimplified here with int and assuming all years have 365 days
        days = int(year_fraction * 365)
        # now convert the year and days into string and then into date (there is probably a better way to do this - without the string step)
        date = datetime.strptime("{}-{}".format(date_year, days),"%Y-%j")  
        # see https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior for format explanation
        dates.append(date)
    deltas.append(dates[1] - dates[0])

# now print outputs
for delta in deltas:
    print(delta.days)
40
задан Brian Tompsett - 汤莱恩 5 February 2016 в 21:34
поделиться

2 ответа

Если вы используете целые числа, используйте макрос MIN () :

MIN(25, 50); //Returns 25

Если вы сравниваете два NSNumber , то используйте метод compare: :

NSNumber *number, *secondNumber; //Assume 'number'=25, 'secondNumber'=50
NSComparisonResult result = [number compare:secondNumber];

return (result==NSOrderedDescending)?secondNumber:number; //Returns the 'number' NSNumber
81
ответ дан 27 November 2019 в 01:03
поделиться

Стандартная библиотека C включает несколько функций min () , которые по двум числам возвращают нижнее значение из двух:

 double fmin(double x, double y);
 long double fminl(long double x, long double y);
 float fminf(float x, float y);

Чтобы использовать их, просто #include .

55
ответ дан 27 November 2019 в 01:03
поделиться
Другие вопросы по тегам:

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