pvjc22/a1/program.c

345 lines
7.3 KiB
C
Raw Normal View History

2022-03-31 08:46:47 +00:00
#include <stdio.h>
2022-03-31 09:37:34 +00:00
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
2022-03-31 09:56:39 +00:00
int main()
{
char riadok[999][999];
int i = 0;
int o = 0;
int need = 0;
2022-03-31 09:37:34 +00:00
bool first;
2022-03-31 09:56:39 +00:00
while (1)
{
2022-03-31 09:37:34 +00:00
o = 0;
2022-03-31 09:56:39 +00:00
while (1)
{
2022-03-31 09:37:34 +00:00
riadok[i][o] = getchar();
2022-03-31 09:56:39 +00:00
if (riadok[i][o] == '\n')
{
2022-03-31 09:37:34 +00:00
first = true;
need++;
break;
}
2022-03-31 09:56:39 +00:00
2022-03-31 09:37:34 +00:00
o++;
}
2022-03-31 09:56:39 +00:00
if (first == true && riadok[i][0] == '\n')
{
2022-03-31 09:37:34 +00:00
break;
}
i++;
}
2022-03-31 09:56:39 +00:00
for (int j = 0; j < need - 1; j++)
{
for (int g = 0; g < strlen(riadok[j]); g++)
{
if (riadok[j][g] != '.' && riadok[j][g] != '1' && riadok[j][g] != '2' && riadok[j][g] != '3' && riadok[j][g] != '4' && riadok[j][g] != '5' && riadok[j][g] != '6' && riadok[j][g] != '7' && riadok[j][g] != '8' && riadok[j][g] != '9' && riadok[j][g] != '0' && riadok[j][g] != '\n' && riadok[j][g] != '\0')
{
2022-03-31 09:37:34 +00:00
riadok[j][0] = '9';
riadok[j][1] = '.';
riadok[j][2] = '9';
riadok[j][3] = '.';
riadok[j][4] = '9';
riadok[j][5] = '.';
riadok[j][6] = '\0';
break;
}
}
}
i = 0;
2022-03-31 09:56:39 +00:00
for (int j = 0; j < need - 1; j++)
{
2022-03-31 09:37:34 +00:00
i = 1;
2022-03-31 09:56:39 +00:00
for (int g = 0; g < strlen(riadok[j]); g++)
{
2022-03-31 10:00:38 +00:00
if ((riadok[j][g] == '1' || riadok[j][g] == '2' || riadok[j][g] == '3' || riadok[j][g] == '4' || riadok[j][g] == '5' || riadok[j][g] == '6' || riadok[j][g] == '7' || riadok[j][g] == '8' || riadok[j][g] == '9' || riadok[j][g] == '0' || riadok[j][g] == '\0'))
2022-03-31 09:56:39 +00:00
{
2022-03-31 09:37:34 +00:00
i++;
2022-03-31 09:56:39 +00:00
if (strlen(riadok[j]) == i)
{
2022-03-31 09:37:34 +00:00
riadok[j][0] = '9';
riadok[j][1] = '.';
riadok[j][2] = '9';
riadok[j][3] = '.';
riadok[j][4] = '9';
riadok[j][5] = '.';
riadok[j][6] = '\0';
break;
}
}
}
}
2022-03-31 09:56:39 +00:00
for (int j = 0; j < need - 1; j++)
{
if (riadok[j][0] == '0')
{
2022-03-31 09:37:34 +00:00
riadok[j][0] = '9';
riadok[j][1] = '.';
riadok[j][2] = '9';
riadok[j][3] = '.';
riadok[j][4] = '9';
riadok[j][5] = '.';
riadok[j][6] = '\0';
}
}
2022-03-31 09:56:39 +00:00
for (int j = 0; j < need - 1; j++)
{
for (int g = 0; g < strlen(riadok[j]); g++)
{
if (riadok[j][g] == '0' && riadok[j][g - 1] == '.')
{
2022-03-31 09:37:34 +00:00
riadok[j][0] = '9';
riadok[j][1] = '.';
riadok[j][2] = '9';
riadok[j][3] = '.';
riadok[j][4] = '9';
riadok[j][5] = '.';
riadok[j][6] = '\0';
}
}
}
2022-03-31 09:56:39 +00:00
char riadok1[999];
2022-03-31 09:37:34 +00:00
i = 0;
2022-03-31 09:56:39 +00:00
for (int j = 0; j < need - 1; j++)
{
for (int g = 0; g < strlen(riadok[j]); g++)
{
if (riadok[j][g] == '\n')
{
2022-03-31 09:37:34 +00:00
riadok[j][g] = '.';
}
2022-03-31 09:56:39 +00:00
if (riadok[j][g] != '\0')
{
2022-03-31 09:37:34 +00:00
riadok1[i] = riadok[j][g];
i++;
}
}
}
riadok1[i] = '\0';
int len = strlen(riadok1);
int s = 0;
2022-03-31 09:56:39 +00:00
for (int j = 0; j < len; j++)
{
if (riadok1[j] == '.')
{
2022-03-31 09:37:34 +00:00
s++;
}
}
char *endptr = NULL;
char *start = riadok1;
2022-03-31 09:56:39 +00:00
int cisla[s];
2022-03-31 09:37:34 +00:00
i = 0;
2022-03-31 09:56:39 +00:00
while (start < (riadok1 + len))
{
cisla[i] = strtol(start, &endptr, 10);
if (cisla[i])
{
2022-03-31 09:37:34 +00:00
start = endptr + 1;
2022-03-31 09:56:39 +00:00
}
2022-03-31 09:37:34 +00:00
else
2022-03-31 09:56:39 +00:00
{
2022-03-31 09:37:34 +00:00
break;
2022-03-31 09:56:39 +00:00
}
2022-03-31 09:37:34 +00:00
i++;
}
2022-03-31 09:56:39 +00:00
2022-03-31 09:37:34 +00:00
need = 0;
2022-03-31 09:56:39 +00:00
for (int j = 0; j < s; j = j + 3)
{
2022-03-31 10:00:38 +00:00
if (cisla[j + 1] > 12 || cisla[j + 1] < 0 || cisla[j] < 1 || cisla[j] > 31 || cisla[j + 2] < 1900 || cisla[j + 2] > 2100)
2022-03-31 09:56:39 +00:00
{
cisla[j] = 0;
cisla[j + 1] = 0;
cisla[j + 2] = 0;
2022-03-31 09:37:34 +00:00
need++;
}
}
2022-03-31 09:56:39 +00:00
for (int j = 0; j < s; j = j + 3)
{
if (cisla[j + 1] == 2 && cisla[j] == 29 && cisla[j + 2] % 4 != 0)
{
cisla[j] = 0;
cisla[j + 1] = 0;
cisla[j + 2] = 0;
2022-03-31 09:37:34 +00:00
need++;
}
}
2022-03-31 09:56:39 +00:00
for (int j = 0; j < s; j = j + 3)
{
if (cisla[j + 1] == 1 && cisla[j] > 0 && cisla[j] <= 31)
{
if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
}
else if (cisla[j] > 24)
{
cisla[j] = cisla[j] + 7 - 31;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 2 && cisla[j] > 0 && cisla[j] <= 28 && cisla[j + 2] % 4 != 0)
{
if (cisla[j] <= 21)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 21)
{
cisla[j] = cisla[j] + 7 - 28;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 2 && cisla[j] > 0 && cisla[j] <= 29 && cisla[j + 2] % 4 == 0)
{
if (cisla[j] <= 22)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 22)
{
cisla[j] = cisla[j] + 7 - 29;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 3 && cisla[j] > 0 && cisla[j] <= 31)
{
if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 24)
{
cisla[j] = cisla[j] + 7 - 31;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 4 && cisla[j] > 0 && cisla[j] <= 30)
{
if (cisla[j] <= 23)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 23)
{
cisla[j] = cisla[j] + 7 - 30;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 5 && cisla[j] > 0 && cisla[j] <= 31)
{
if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 24)
{
cisla[j] = cisla[j] + 7 - 31;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 6 && cisla[j] > 0 && cisla[j] <= 30)
{
if (cisla[j] <= 23)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 23)
{
cisla[j] = cisla[j] + 7 - 30;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 7 && cisla[j] > 0 && cisla[j] <= 31)
{
if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 24)
{
2022-03-31 09:37:34 +00:00
2022-03-31 09:56:39 +00:00
cisla[j] = cisla[j] + 7 - 31;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 8 && cisla[j] > 0 && cisla[j] <= 31)
{
if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 24)
{
cisla[j] = cisla[j] + 7 - 31;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 9 && cisla[j] > 0 && cisla[j] <= 30)
{
if (cisla[j] <= 23)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 23)
{
cisla[j] = cisla[j] + 7 - 30;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 10 && cisla[j] > 0 && cisla[j] <= 31)
{
if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 24)
{
cisla[j] = cisla[j] + 7 - 31;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 11 && cisla[j] > 0 && cisla[j] <= 30)
{
if (cisla[j] <= 23)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 23)
{
cisla[j] = cisla[j] + 7 - 30;
cisla[j + 1]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
else if (cisla[j + 1] == 12 && cisla[j] > 0 && cisla[j] <= 31)
{
if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] > 24)
{
cisla[j] = cisla[j] + 7 - 31;
cisla[j + 1] = 1;
cisla[j + 2]++;
2022-03-31 09:37:34 +00:00
}
}
2022-03-31 09:56:39 +00:00
if (cisla[j] != 0 && cisla[j + 1] != 0 && cisla[j + 2] != 0)
{
printf("%d.%d.%d\n\n", cisla[j], cisla[j + 1], cisla[j + 2]);
2022-03-31 09:37:34 +00:00
}
2022-03-31 09:56:39 +00:00
else if (cisla[j] == 0 && cisla[j + 1] == 0 && cisla[j + 2] == 0)
{
2022-03-31 09:37:34 +00:00
puts("Neplatny datum.");
}
}
}