Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <cstdio>
- #define MaxNombreEstacion 35
- using namespace std;
- double calcularTiempo(int hrI, int minI, int segI, int hrF, int minF, int segF) {
- double tiempo;
- if (hrI > hrF) tiempo = (23 - hrI)*3600 + (59 - minI)*60 + (60 - segI);
- else if (minI > minF) tiempo = (hrF - hrI)*3600 + (59 - minI)*60 + (60 - segF) + minF * 60 + segF;
- else if (segI > segF) tiempo = (hrF - hrI - 1)*3600 + (minF - minI - 1)*60 + (60 - segF) + segF;
- else tiempo = (hrF * 3600 + minF * 60 + segF)-(hrI * 3600 + minI * 60 + segI);
- return tiempo;
- }
- int main(int argc, char** argv) {
- char c;
- int codigo, tamanoNombre, hayfecha, contadorReg, contadorTotalReg;
- int dd, mm, aaaa, ddAux, mmAux, aaaaAux, horaIaux, minIaux, segIaux, horaFaux, minFaux, segFaux, horaA, minA, segA;
- int tamanoHoraI, tamanoHoraF, horaI, minI, segI, horaF, minF, segF;
- int acumuladoTReg;
- float precipitacion, precipitacionAux, precipitacionReg;
- float promedio;
- for (int i = 0; i < 80; i++) printf("=");
- printf("\n");
- printf("%-35s%s\n", " ", "INFORME DE PRECIPITACIONES");
- for (int i = 0; i < 80; i++) printf("=");
- contadorTotalReg = 0;
- while (1) {
- printf("\n");
- printf("%-36s%-32s%-10s", " ESTACION", "CIUDAD", "DEPARTAMENTO");
- printf("\n");
- for (int i = 0; i < 80; i++) printf("-");
- printf("\n");
- tamanoNombre = 0;
- while ((c = getchar()) != ',') { //Estacion
- if (tamanoNombre < MaxNombreEstacion) {
- putchar(c);
- tamanoNombre++;
- }
- }
- while (tamanoNombre < MaxNombreEstacion) {
- putchar(' ');
- tamanoNombre++;
- }
- tamanoNombre = 0;
- while ((c = getchar()) != ',') { //Ciudad
- if (tamanoNombre < MaxNombreEstacion) {
- putchar(c);
- tamanoNombre++;
- }
- }
- while (tamanoNombre < MaxNombreEstacion - 3) {
- putchar(' ');
- tamanoNombre++;
- }
- tamanoNombre = 0;
- while ((c = getchar()) != ':') { //Departamento
- if (tamanoNombre < MaxNombreEstacion) {
- putchar(c);
- tamanoNombre++;
- }
- }
- if (c == ':') printf("\n");
- printf("\n%-15s%-15s%-20s%-20s%-5s\n", " Fecha", "cantidad", "Tiempo Total", "Total Llovido", "Promedio");
- //printf("\n");
- scanf("%d/%d/%d", &dd, &mm, &aaaa); //Lectura Fecha Inicial
- //printf(" %d/%d/%-2d",dd,mm,aaaa);
- horaI = minI = segI = horaF = minF = segF = 0;
- scanf("%d:%d:%d", &horaI, &minI, &segI);
- scanf("%d:%d:%d", &horaF, &minF, &segF);
- scanf("%fl", &precipitacion);
- contadorReg = 1;
- acumuladoTReg = 0;
- precipitacionReg = precipitacion;
- while (1) {
- hayfecha = scanf("%d/%d/%d", &ddAux, &mmAux, &aaaaAux); //Lectura Fecha Secundaria
- if (hayfecha == 3) { // Si encuentra fecha
- scanf("%d:%d:%d", &horaIaux, &minIaux, &segIaux);
- scanf("%d:%d:%d", &horaFaux, &minFaux, &segFaux);
- scanf("%fl", &precipitacionAux);
- if ((dd == ddAux) && (mm = mmAux) && (aaaa == aaaaAux)) { //Si encontro fecha igual
- contadorReg++;
- acumuladoTReg += calcularTiempo(horaI, minI, segI, horaF, minF, segF) + calcularTiempo(horaIaux, minIaux, segIaux, horaFaux, minFaux, segFaux);
- //acumuladoTReg += ((horaF*3600 + minF*60 + segF) - (horaI*3660 + minI*60 + segI)) + ((horaFaux*3600 + minFaux*60 + segFaux) - (horaIaux*3660 + minIaux*60 + segIaux));
- precipitacionReg += precipitacionAux;
- } else {
- horaA = (int) acumuladoTReg / 3600;
- minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
- segA = acumuladoTReg - 3600 * horaA - 60 * minA;
- promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
- printf(" %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
- dd = ddAux;
- mm = mmAux;
- aaaa = aaaaAux;
- horaI = horaIaux;
- minI = minIaux;
- segI = segIaux;
- horaF = horaFaux;
- minF = minFaux;
- segF = segFaux;
- precipitacion = precipitacionAux;
- }
- }
- if (hayfecha == 0) { //Fin de linea
- horaA = (int) acumuladoTReg / 3600;
- minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
- segA = acumuladoTReg - 3600 * horaA - 60 * minA;
- promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
- printf(" %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
- break;
- } else if (hayfecha == EOF) {
- horaA = (int) acumuladoTReg / 3600;
- minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
- segA = acumuladoTReg - 3600 * horaA - 60 * minA;
- promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
- printf(" %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
- break;
- }
- }
- for (int i = 0; i < 80; i++) printf("-");
- printf("\n");
- printf(" Resumen:\n");
- if (hayfecha == EOF)
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement