Advertisement
xlujiax

Untitled

Aug 31st, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <cstdio>
  3.  
  4. #define MaxNombreEstacion 35
  5.  
  6. using namespace std;
  7.  
  8. double calcularTiempo(int hrI, int minI, int segI, int hrF, int minF, int segF) {
  9. double tiempo;
  10. if (hrI > hrF) tiempo = (23 - hrI)*3600 + (59 - minI)*60 + (60 - segI);
  11. else if (minI > minF) tiempo = (hrF - hrI)*3600 + (59 - minI)*60 + (60 - segF) + minF * 60 + segF;
  12. else if (segI > segF) tiempo = (hrF - hrI - 1)*3600 + (minF - minI - 1)*60 + (60 - segF) + segF;
  13. else tiempo = (hrF * 3600 + minF * 60 + segF)-(hrI * 3600 + minI * 60 + segI);
  14. return tiempo;
  15. }
  16.  
  17. int main(int argc, char** argv) {
  18. char c;
  19. int codigo, tamanoNombre, hayfecha, contadorReg, contadorTotalReg;
  20. int dd, mm, aaaa, ddAux, mmAux, aaaaAux, horaIaux, minIaux, segIaux, horaFaux, minFaux, segFaux, horaA, minA, segA;
  21. int tamanoHoraI, tamanoHoraF, horaI, minI, segI, horaF, minF, segF;
  22. int acumuladoTReg;
  23. float precipitacion, precipitacionAux, precipitacionReg;
  24. float promedio;
  25. for (int i = 0; i < 80; i++) printf("=");
  26. printf("\n");
  27. printf("%-35s%s\n", " ", "INFORME DE PRECIPITACIONES");
  28. for (int i = 0; i < 80; i++) printf("=");
  29.  
  30. contadorTotalReg = 0;
  31. while (1) {
  32. printf("\n");
  33. printf("%-36s%-32s%-10s", " ESTACION", "CIUDAD", "DEPARTAMENTO");
  34. printf("\n");
  35. for (int i = 0; i < 80; i++) printf("-");
  36. printf("\n");
  37. tamanoNombre = 0;
  38. while ((c = getchar()) != ',') { //Estacion
  39. if (tamanoNombre < MaxNombreEstacion) {
  40. putchar(c);
  41. tamanoNombre++;
  42. }
  43. }
  44. while (tamanoNombre < MaxNombreEstacion) {
  45. putchar(' ');
  46. tamanoNombre++;
  47. }
  48.  
  49. tamanoNombre = 0;
  50. while ((c = getchar()) != ',') { //Ciudad
  51. if (tamanoNombre < MaxNombreEstacion) {
  52. putchar(c);
  53. tamanoNombre++;
  54. }
  55. }
  56. while (tamanoNombre < MaxNombreEstacion - 3) {
  57. putchar(' ');
  58. tamanoNombre++;
  59. }
  60.  
  61. tamanoNombre = 0;
  62. while ((c = getchar()) != ':') { //Departamento
  63. if (tamanoNombre < MaxNombreEstacion) {
  64. putchar(c);
  65. tamanoNombre++;
  66. }
  67. }
  68. if (c == ':') printf("\n");
  69. printf("\n%-15s%-15s%-20s%-20s%-5s\n", " Fecha", "cantidad", "Tiempo Total", "Total Llovido", "Promedio");
  70.  
  71. //printf("\n");
  72.  
  73. scanf("%d/%d/%d", &dd, &mm, &aaaa); //Lectura Fecha Inicial
  74. //printf(" %d/%d/%-2d",dd,mm,aaaa);
  75. horaI = minI = segI = horaF = minF = segF = 0;
  76. scanf("%d:%d:%d", &horaI, &minI, &segI);
  77. scanf("%d:%d:%d", &horaF, &minF, &segF);
  78. scanf("%fl", &precipitacion);
  79.  
  80. contadorReg = 1;
  81. acumuladoTReg = 0;
  82. precipitacionReg = precipitacion;
  83. while (1) {
  84. hayfecha = scanf("%d/%d/%d", &ddAux, &mmAux, &aaaaAux); //Lectura Fecha Secundaria
  85. if (hayfecha == 3) { // Si encuentra fecha
  86. scanf("%d:%d:%d", &horaIaux, &minIaux, &segIaux);
  87. scanf("%d:%d:%d", &horaFaux, &minFaux, &segFaux);
  88. scanf("%fl", &precipitacionAux);
  89. if ((dd == ddAux) && (mm = mmAux) && (aaaa == aaaaAux)) { //Si encontro fecha igual
  90. contadorReg++;
  91. acumuladoTReg += calcularTiempo(horaI, minI, segI, horaF, minF, segF) + calcularTiempo(horaIaux, minIaux, segIaux, horaFaux, minFaux, segFaux);
  92. //acumuladoTReg += ((horaF*3600 + minF*60 + segF) - (horaI*3660 + minI*60 + segI)) + ((horaFaux*3600 + minFaux*60 + segFaux) - (horaIaux*3660 + minIaux*60 + segIaux));
  93. precipitacionReg += precipitacionAux;
  94. } else {
  95. horaA = (int) acumuladoTReg / 3600;
  96. minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
  97. segA = acumuladoTReg - 3600 * horaA - 60 * minA;
  98. promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
  99. printf(" %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
  100. dd = ddAux;
  101. mm = mmAux;
  102. aaaa = aaaaAux;
  103. horaI = horaIaux;
  104. minI = minIaux;
  105. segI = segIaux;
  106. horaF = horaFaux;
  107. minF = minFaux;
  108. segF = segFaux;
  109. precipitacion = precipitacionAux;
  110. }
  111. }
  112. if (hayfecha == 0) { //Fin de linea
  113. horaA = (int) acumuladoTReg / 3600;
  114. minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
  115. segA = acumuladoTReg - 3600 * horaA - 60 * minA;
  116. promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
  117. printf(" %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
  118. break;
  119. } else if (hayfecha == EOF) {
  120. horaA = (int) acumuladoTReg / 3600;
  121. minA = (int) (acumuladoTReg - 3600 * horaA) / 60;
  122. segA = acumuladoTReg - 3600 * horaA - 60 * minA;
  123. promedio = precipitacionReg / (horaA * 60 + minA + segA / 60);
  124. printf(" %02d/%02d/%-4d %-12d %d:%d:%-15d %7.2fl %14.3fl \n", dd, mm, aaaa, contadorReg, horaA, minA, segA, precipitacionReg, promedio);
  125. break;
  126. }
  127. }
  128. for (int i = 0; i < 80; i++) printf("-");
  129. printf("\n");
  130. printf(" Resumen:\n");
  131.  
  132. if (hayfecha == EOF)
  133. break;
  134. }
  135.  
  136.  
  137. return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement