Publi

  • Algoritmos: Repartir el tiempo total de una tarea a lo largo de varios días en C

    Cuando tenemos una tarea que debemos llevar a cabo a largo medio/plazo, normalmente debemos dedicar un tiempo cada día a esa tarea pero, ¿cuánto tiempo necesitamos dedicar a esa tarea (como mínimo) para terminar en un plazo establecido?

    Gracias a Alejandro por la sugerencia de este programa.

    Primero el programa, y luego lo comentamos:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    /**
    *************************************************************
    * @file calcula_horas.c
    *************************************************************/


    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    #include <string.h>

    typedef struct
    {
      int hours;
      int minutes;
      float raw;
    } Thm;

    time_t getTime(int day, int month, int year);
    int calculateDaysInRange(int daysInRange[7], time_t start, time_t end);
    int calculateTotalDays(int workDays[7], int daysInRange[7]);
    int calculateHoursADay(Thm *result, int totalDays, int hoursToWork, int totalHours);

    int main(int argc, char *argv[])
    {
      int error;
      int i ;
      int totalDays;
      time_t start = getTime(1, 6, 2013);
      time_t end = getTime(18, 6, 2013);
      /* Which days can we work in this task?
    Leer artículo completo