Изменил(а) на 'a1/program.c'

This commit is contained in:
Yaroslav Orlianskyi 2022-03-31 09:56:39 +00:00
parent b41b4e9745
commit 212423b7d9

View File

@ -2,30 +2,42 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
int main()
int main(){ {
char riadok[499][499]; char riadok[999][999];
int i, o , need = 0; int i = 0;
int o = 0;
int need = 0;
bool first; bool first;
while (1){ while (1)
{
o = 0; o = 0;
while (1){ while (1)
{
riadok[i][o] = getchar(); riadok[i][o] = getchar();
if (riadok[i][o] == '\n'){
if (riadok[i][o] == '\n')
{
first = true; first = true;
need++; need++;
break; break;
} }
o++; o++;
} }
if (first == true && riadok[i][0] == '\n'){ if (first == true && riadok[i][0] == '\n')
{
break; break;
} }
i++; i++;
} }
for (int j = 0; j < need - 1; j++){ 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'){ 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')
{
riadok[j][0] = '9'; riadok[j][0] = '9';
riadok[j][1] = '.'; riadok[j][1] = '.';
riadok[j][2] = '9'; riadok[j][2] = '9';
@ -38,12 +50,16 @@ int main(){
} }
} }
i = 0; i = 0;
for (int j = 0; j < need - 1; j++){ for (int j = 0; j < need - 1; j++)
{
i = 1; i = 1;
for (int g = 0; g < strlen(riadok[j]); g++){ for (int g = 0; g < strlen(riadok[j]); g++)
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')){ {
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'))
{
i++; i++;
if (strlen(riadok[j]) == i){ if (strlen(riadok[j]) == i)
{
riadok[j][0] = '9'; riadok[j][0] = '9';
riadok[j][1] = '.'; riadok[j][1] = '.';
riadok[j][2] = '9'; riadok[j][2] = '9';
@ -56,8 +72,11 @@ int main(){
} }
} }
} }
for (int j = 0; j < need - 1; j++){
if (riadok[j][0] == '0'){ for (int j = 0; j < need - 1; j++)
{
if (riadok[j][0] == '0')
{
riadok[j][0] = '9'; riadok[j][0] = '9';
riadok[j][1] = '.'; riadok[j][1] = '.';
riadok[j][2] = '9'; riadok[j][2] = '9';
@ -67,9 +86,13 @@ int main(){
riadok[j][6] = '\0'; riadok[j][6] = '\0';
} }
} }
for (int j = 0; j < need - 1; j++){
for (int g = 0; g < strlen(riadok[j]); g++){ for (int j = 0; j < need - 1; j++)
if (riadok[j][g] == '0' && riadok[j][g - 1] == '.'){ {
for (int g = 0; g < strlen(riadok[j]); g++)
{
if (riadok[j][g] == '0' && riadok[j][g - 1] == '.')
{
riadok[j][0] = '9'; riadok[j][0] = '9';
riadok[j][1] = '.'; riadok[j][1] = '.';
riadok[j][2] = '9'; riadok[j][2] = '9';
@ -80,14 +103,19 @@ int main(){
} }
} }
} }
char riadok1[499];
char riadok1[999];
i = 0; i = 0;
for (int j = 0; j < need - 1; j++){ for (int j = 0; j < need - 1; j++)
for (int g = 0; g < strlen(riadok[j]); g++){ {
if (riadok[j][g] == '\n'){ for (int g = 0; g < strlen(riadok[j]); g++)
{
if (riadok[j][g] == '\n')
{
riadok[j][g] = '.'; riadok[j][g] = '.';
} }
if (riadok[j][g] != '\0'){ if (riadok[j][g] != '\0')
{
riadok1[i] = riadok[j][g]; riadok1[i] = riadok[j][g];
i++; i++;
} }
@ -96,163 +124,221 @@ int main(){
riadok1[i] = '\0'; riadok1[i] = '\0';
int len = strlen(riadok1); int len = strlen(riadok1);
int s = 0; int s = 0;
for (int j = 0; j < len; j++){ for (int j = 0; j < len; j++)
if (riadok1[j] == '.'){ {
if (riadok1[j] == '.')
{
s++; s++;
} }
} }
char *endptr = NULL; char *endptr = NULL;
char *start = riadok1; char *start = riadok1;
int number[s]; int cisla[s];
i = 0; i = 0;
while (start < (riadok1 + len)){ while (start < (riadok1 + len))
number[i] = strtol(start, &endptr, 10); {
if (number[i]) cisla[i] = strtol(start, &endptr, 10);
if (cisla[i])
{
start = endptr + 1; start = endptr + 1;
}
else else
{
break; break;
}
i++; i++;
} }
need = 0;
for (int j = 0; j < s; j = j + 3){
if (number[j + 1] > 12 || number[j + 1] < 0 || number[j] < 1 || number[j] > 31 || number[j + 2] < 1900 || number[j + 2] > 2100){
number[j] = 0;
number[j + 1] = 0;
number[j + 2] = 0;
need++;
}
}
for (int j = 0; j < s; j = j + 3){
if (number[j + 1] == 2 && number[j] == 29 && number[j + 2] % 4 != 0) {
number[j] = 0;
number[j + 1] = 0;
number[j + 2] = 0;
need++;
}
}
for (int j = 0; j < s; j = j + 3){
if (number[j + 1] == 1 && number[j] > 0 && number[j] <= 31){
if (number[j] <= 24)
number[j] = number[j] + 7;
else if (number[j] > 24){
number[j] = number[j] + 7 - 31;
number[j + 1]++;
}
}
else if (number[j + 1] == 2 && number[j] > 0 && number[j] <= 28 && number[j + 2] % 4 != 0){
if (number[j] <= 21){
number[j] = number[j] + 7;
}
else if (number[j] > 21){
number[j] = number[j] + 7 - 28;
number[j + 1]++;
}
}
else if (number[j + 1] == 2 && number[j] > 0 && number[j] <= 29 && number[j + 2] % 4 == 0){
if (number[j] <= 22){
number[j] = number[j] + 7;
}
else if (number[j] > 22){
number[j] = number[j] + 7 - 29;
number[j + 1]++;
}
}
else if (number[j + 1] == 3 && number[j] > 0 && number[j] <= 31){
if (number[j] <= 24){
number[j] = number[j] + 7;
}
else if (number[j] > 24){
number[j] = number[j] + 7 - 31;
number[j + 1]++;
}
}
else if (number[j + 1] == 4 && number[j] > 0 && number[j] <= 30){
if (number[j] <= 23){
number[j] = number[j] + 7;
}
else if (number[j] > 23){
number[j] = number[j] + 7 - 30;
number[j + 1]++;
}
}
else if (number[j + 1] == 5 && number[j] > 0 && number[j] <= 31){
if (number[j] <= 24){
number[j] = number[j] + 7;
}
else if (number[j] > 24){
number[j] = number[j] + 7 - 31;
number[j + 1]++;
}
}
else if (number[j + 1] == 6 && number[j] > 0 && number[j] <= 30){
if (number[j] <= 23){
number[j] = number[j] + 7;
}
else if (number[j] > 23){
number[j] = number[j] + 7 - 30;
number[j + 1]++;
}
}
else if (number[j + 1] == 7 && number[j] > 0 && number[j] <= 31){
if (number[j] <= 24){
number[j] = number[j] + 7;
}
else if (number[j] > 24){
number[j] = number[j] + 7 - 31; need = 0;
number[j + 1]++; for (int j = 0; j < s; j = j + 3)
{
if (cisla[j + 1] > 12 cisla[j + 1] < 0 cisla[j] < 1 cisla[j] > 31 cisla[j + 2] < 1900 cisla[j + 2] > 2100)
{
cisla[j] = 0;
cisla[j + 1] = 0;
cisla[j + 2] = 0;
need++;
}
}
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;
need++;
}
}
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]++;
} }
} }
else if (number[j + 1] == 8 && number[j] > 0 && number[j] <= 31){ else if (cisla[j + 1] == 2 && cisla[j] > 0 && cisla[j] <= 28 && cisla[j + 2] % 4 != 0)
if (number[j] <= 24){ {
number[j] = number[j] + 7; if (cisla[j] <= 21)
{
cisla[j] = cisla[j] + 7;
} }
else if (number[j] > 24){ else if (cisla[j] > 21)
number[j] = number[j] + 7 - 31; {
number[j + 1]++; cisla[j] = cisla[j] + 7 - 28;
cisla[j + 1]++;
} }
} }
else if (number[j + 1] == 9 && number[j] > 0 && number[j] <= 30){ else if (cisla[j + 1] == 2 && cisla[j] > 0 && cisla[j] <= 29 && cisla[j + 2] % 4 == 0)
if (number[j] <= 23){ {
number[j] = number[j] + 7; if (cisla[j] <= 22)
{
cisla[j] = cisla[j] + 7;
} }
else if (number[j] > 23){ else if (cisla[j] > 22)
number[j] = number[j] + 7 - 30; {
number[j + 1]++; cisla[j] = cisla[j] + 7 - 29;
cisla[j + 1]++;
} }
} }
else if (number[j + 1] == 10 && number[j] > 0 && number[j] <= 31){ else if (cisla[j + 1] == 3 && cisla[j] > 0 && cisla[j] <= 31)
if (number[j] <= 24){ {
number[j] = number[j] + 7; if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
} }
else if (number[j] > 24){ else if (cisla[j] > 24)
number[j] = number[j] + 7 - 31; {
number[j + 1]++; cisla[j] = cisla[j] + 7 - 31;
cisla[j + 1]++;
} }
} }
else if (number[j + 1] == 11 && number[j] > 0 && number[j] <= 30){ else if (cisla[j + 1] == 4 && cisla[j] > 0 && cisla[j] <= 30)
if (number[j] <= 23){ {
number[j] = number[j] + 7; if (cisla[j] <= 23)
{
cisla[j] = cisla[j] + 7;
} }
else if (number[j] > 23){ else if (cisla[j] > 23)
number[j] = number[j] + 7 - 30; {
number[j + 1]++; cisla[j] = cisla[j] + 7 - 30;
cisla[j + 1]++;
} }
} }
else if (number[j + 1] == 12 && number[j] > 0 && number[j] <= 31){ else if (cisla[j + 1] == 5 && cisla[j] > 0 && cisla[j] <= 31)
if (number[j] <= 24){ {
number[j] = number[j] + 7; if (cisla[j] <= 24)
{
cisla[j] = cisla[j] + 7;
} }
else if (number[j] > 24){ else if (cisla[j] > 24)
number[j] = number[j] + 7 - 31; {
number[j + 1] = 1; cisla[j] = cisla[j] + 7 - 31;
number[j + 2]++; cisla[j + 1]++;
} }
} }
if (number[j] != 0 && number[j + 1] != 0 && number[j + 2] != 0){ else if (cisla[j + 1] == 6 && cisla[j] > 0 && cisla[j] <= 30)
printf("%d.%d.%d\n\n", number[j], number[j + 1], number[j + 2]); {
if (cisla[j] <= 23)
{
cisla[j] = cisla[j] + 7;
}
else if (cisla[j] > 23)
{
cisla[j] = cisla[j] + 7 - 30;
cisla[j + 1]++;
}
} }
else if (number[j] == 0 && number[j + 1] == 0 && number[j + 2] == 0){ else if (cisla[j + 1] == 7 && 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]++;
}
}
else if (cisla[j + 1] == 8 && 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]++;
}
}
else if (cisla[j + 1] == 9 && cisla[j] > 0 && cisla[j] <= 30)
{
if (cisla[j] <= 23)
{
cisla[j] = cisla[j] + 7;
}
else if (cisla[j] > 23)
{
cisla[j] = cisla[j] + 7 - 30;
cisla[j + 1]++;
}
}
else if (cisla[j + 1] == 10 && 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]++;
}
}
else if (cisla[j + 1] == 11 && cisla[j] > 0 && cisla[j] <= 30)
{
if (cisla[j] <= 23)
{
cisla[j] = cisla[j] + 7;
}
else if (cisla[j] > 23)
{
cisla[j] = cisla[j] + 7 - 30;
cisla[j + 1]++;
}
}
else if (cisla[j + 1] == 12 && 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] = 1;
cisla[j + 2]++;
}
}
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]);
}
else if (cisla[j] == 0 && cisla[j + 1] == 0 && cisla[j + 2] == 0)
{
puts("Neplatny datum."); puts("Neplatny datum.");
} }
} }