#include <stdio.h>
#include <string.h>
#include <sys/types.h>
struct Date {
int day, month, year;
};
struct Subject {
int id;
char name_of_subject[100];
double ects;
};
struct Grade {
char namesurname[100];
int grade_value;
struct Subject subject;
struct Date date;
};
int num_digit(int n) {
int num = 0;
while (n != 0) {
num++;
n /= 10;
}
return num;
}
int check_digits(int d, int m, int y) {
int c0 = 0, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0,
c9 = 0;
int num_digit_day = num_digit(d);
int num_digit_month = num_digit(m);
int num_digit_year = num_digit(y);
if (num_digit_day == 1) {
if (d == 0)
c0 = 1;
if (d == 1)
c1 = 1;
if (d == 2)
c2 = 1;
if (d == 3)
c3 = 1;
if (d == 4)
c4 = 1;
if (d == 5)
c5 = 1;
if (d == 6)
c6 = 1;
if (d == 7)
c7 = 1;
if (d == 8)
c8 = 1;
if (d == 9)
c9 = 1;
}
if (num_digit_day == 2) {
int first_digit_day = d / 10, second_digit_day = d % 10;
if (first_digit_day == 0)
c0 = 1;
if (first_digit_day == 1)
c1 = 1;
if (first_digit_day == 2)
c2 = 1;
if (first_digit_day == 3)
c3 = 1;
if (first_digit_day == 4)
c4 = 1;
if (first_digit_day == 5)
c5 = 1;
if (first_digit_day == 6)
c6 = 1;
if (first_digit_day == 7)
c7 = 1;
if (first_digit_day == 8)
c8 = 1;
if (first_digit_day == 9)
c9 = 1;
if (second_digit_day == 0)
c0 = 1;
if (second_digit_day == 1)
c1 = 1;
if (second_digit_day == 2)
c2 = 1;
if (second_digit_day == 3)
c3 = 1;
if (second_digit_day == 4)
c4 = 1;
if (second_digit_day == 5)
c5 = 1;
if (second_digit_day == 6)
c6 = 1;
if (second_digit_day == 7)
c7 = 1;
if (second_digit_day == 8)
c8 = 1;
if (second_digit_day == 9)
c9 = 1;
}
if (num_digit_month == 1) {
if (m == 0)
c0 = 0;
if (m == 1)
c1 = 1;
if (m == 2)
c2 = 1;
if (m == 3)
c3 = 1;
if (m == 4)
c4 = 1;
if (m == 5)
c5 = 1;
if (m == 6)
c6 = 1;
if (m == 7)
c7 = 1;
if (m == 8)
c8 = 1;
if (m == 9)
c9 = 1;
}
if (num_digit_month == 2) {
int first_digit_month = m / 10, second_digit_month = m % 10;
if (first_digit_month == 0)
c0 = 1;
if (first_digit_month == 1)
c1 = 1;
if (first_digit_month == 2)
c2 = 1;
if (first_digit_month == 3)
c3 = 1;
if (first_digit_month == 4)
c4 = 1;
if (first_digit_month == 5)
c5 = 1;
if (first_digit_month == 6)
c6 = 1;
if (first_digit_month == 7)
c7 = 1;
if (first_digit_month == 8)
c8 = 1;
if (first_digit_month == 9)
c9 = 1;
if (second_digit_month == 0)
c0 = 1;
if (second_digit_month == 1)
c1 = 1;
if (second_digit_month == 2)
c2 = 1;
if (second_digit_month == 3)
c3 = 1;
if (second_digit_month == 4)
c4 = 1;
if (second_digit_month == 5)
c5 = 1;
if (second_digit_month == 6)
c6 = 1;
if (second_digit_month == 7)
c7 = 1;
if (second_digit_month == 8)
c8 = 1;
if (second_digit_month == 9)
c9 = 1;
}
if (num_digit_year == 4) {
int first_digit_year = y / 1000, second_digit_year = y / 100 % 10,
third_digit_year = y / 10 % 10, fourt_digit_year = y % 10;
if (first_digit_year == 0)
c0 = 1;
if (first_digit_year == 1)
c1 = 1;
if (first_digit_year == 2)
c2 = 1;
if (first_digit_year == 3)
c3 = 1;
if (first_digit_year == 4)
c4 = 1;
if (first_digit_year == 5)
c5 = 1;
if (first_digit_year == 6)
c6 = 1;
if (first_digit_year == 7)
c7 = 1;
if (first_digit_year == 8)
c8 = 1;
if (first_digit_year == 9)
c9 = 1;
if (second_digit_year == 0)
c0 = 1;
if (second_digit_year == 1)
c1 = 1;
if (second_digit_year == 2)
c2 = 1;
if (second_digit_year == 3)
c3 = 1;
if (second_digit_year == 4)
c4 = 1;
if (second_digit_year == 5)
c5 = 1;
if (second_digit_year == 6)
c6 = 1;
if (second_digit_year == 7)
c7 = 1;
if (second_digit_year == 8)
c8 = 1;
if (second_digit_year == 9)
c9 = 1;
if (third_digit_year == 0)
c0 = 1;
if (third_digit_year == 1)
c1 = 1;
if (third_digit_year == 2)
c2 = 1;
if (third_digit_year == 3)
c3 = 1;
if (third_digit_year == 4)
c4 = 1;
if (third_digit_year == 5)
c5 = 1;
if (third_digit_year == 6)
c6 = 1;
if (third_digit_year == 7)
c7 = 1;
if (third_digit_year == 8)
c8 = 1;
if (third_digit_year == 9)
c9 = 1;
if (fourt_digit_year == 0)
c0 = 1;
if (fourt_digit_year == 1)
c1 = 1;
if (fourt_digit_year == 2)
c2 = 1;
if (fourt_digit_year == 3)
c3 = 1;
if (fourt_digit_year == 4)
c4 = 1;
if (fourt_digit_year == 5)
c5 = 1;
if (fourt_digit_year == 6)
c6 = 1;
if (fourt_digit_year == 7)
c7 = 1;
if (fourt_digit_year == 8)
c8 = 1;
if (fourt_digit_year == 9)
c9 = 1;
}
return c0 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9;
}
int digits_in_date(struct Grade arr[], int n) {
int i, j, k = -1, num_of_success = -1, min = 0;
double sum_ects;
int s0 = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0, s6 = 0, s7 = 0, s8 = 0,
s9 = 0;
int a0 = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0,
a9 = 0;
for (i = 0; i < n; i++) {
sum_ects = arr[i].subject.ects;
for (j = i + 1; j < n; j++)
if (strcmp(arr[j].namesurname, arr[i].namesurname) == 0)
sum_ects += arr[j].subject.ects;
if (sum_ects >= 30) {
num_of_success++;
if (num_of_success == 0)
a0 = i;
if (num_of_success == 1)
a1 = i;
if (num_of_success == 2)
a2 = i;
if (num_of_success == 3)
a3 = i;
if (num_of_success == 4)
a4 = i;
if (num_of_success == 5)
a5 = i;
if (num_of_success == 6)
a6 = i;
if (num_of_success == 7)
a7 = i;
if (num_of_success == 8)
a8 = i;
if (num_of_success == 9)
a9 = i;
k++;
if (k == 0)
s0 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 1)
s1 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 2)
s2 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 3)
s3 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 4)
s4 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 5)
s5 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 6)
s6 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 7)
s7 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 8)
s8 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
if (k == 9)
s9 = check_digits(arr[i].date.day, arr[i].date.month, arr[i].date.year);
}
}
for (i = 0; i < n; i++) {
if (num_of_success == 0) {
min = s0;
if (i == a0) {
if (check_digits(arr[i].date.day, arr[i].date.month,
arr[i].date.year) == min) {
for (j = i + 1; j < n; j++)
arr[j - 1] = arr[j];
n--;
i--;
}
}
}
if (num_of_success == 1) {
min = s0;
if (s1 < min)
min = s1;
if (i == a0 || i == a1) {
if (check_digits(arr[i].date.day, arr[i].date.month,
arr[i].date.year) == min) {
for (j = i + 1; j < n; j++)
arr[j - 1] = arr[j];
n--;
i--;
}
}
}
if (num_of_success == 2) {
int min = 2000000;
if (s0 < s1 && s0 < s2)
min = s0;
if (s1 < s0 && s1 < s2)
min = s1;
if (s2 < s0 && s2 < s1)
min = s2;
if (i == a0 || i == a1 || i == a2) {
if (check_digits(arr[i].date.day, arr[i].date.month,
arr[i].date.year) == min) {
for (j = i + 1; j < n; j++)
arr[j - 1] = arr[j];
n--;
i--;
}
}
}
if (num_of_success == 3) {
int min = 2000000;
if (s0 < s1 && s0 < s2 && s0 < s3)
min = s0;
if (s1 < s0 && s1 < s2 && s1 < s3)
min = s1;
if (s2 < s0 && s2 < s1 && s2 < s3)
min = s2;
if (s3 < s0 && s3 < s1 && s3 < s2)
min = s3;
if (i == a0 || i == a1 || i == a2 || i == a3) {
if (check_digits(arr[i].date.day, arr[i].date.month,
arr[i].date.year) == min) {
for (j = i + 1; j < n; j++)
arr[j - 1] = arr[j];
n--;
i--;
}
}
}
if (num_of_success == 4) {
int min = 2000000;
if (s0 < s1 && s0 < s2 && s0 < s3 && s0 < s4)
min = s0;
if (s1 < s0 && s1 < s2 && s1 < s3 && s1 < s4)
min = s1;
if (s2 < s0 && s2 < s1 && s2 < s3 && s2 < s4)
min = s2;
if (s3 < s0 && s3 < s1 && s3 < s2 && s3 < s4)
min = s3;
if (s4 < s0 && s4 < s1 && s4 < s2 && s4 < s3)
min = s4;
if (i == a0 || i == a1 || i == a2 || i == a3 || i == a4) {
if (check_digits(arr[i].date.day, arr[i].date.month,
arr[i].date.year) == min) {
for (j = i + 1; j < n; j++)
arr[j - 1] = arr[j];
n--;
i--;
}
}
}
if (num_of_success == 5) {
int min = 2000000;
if (s0 < s1 && s0 < s2 && s0 < s3 && s0 < s4 && s0 < s5)
min = s0;
if (s1 < s0 && s1 < s2 && s1 < s3 && s1 < s4 && s1 < s5)
min = s1;
if (s2 < s0 && s2 < s1 && s2 < s3 && s2 < s4 && s2 < s5)
min = s2;
if (s3 < s0 && s3 < s1 && s3 < s2 && s3 < s4 && s3 < s5)
min = s3;
if (s4 < s0 && s4 < s1 && s4 < s2 && s4 < s3 && s4 < s5)
min = s4;
if (s5 < s0 && s5 < s1 && s5 < s2 && s5 < s3 && s5 < s4)
min = s5;
if (i == a0 || i == a1 || i == a2 || i == a3 || i == a4 || i == a5) {
if (check_digits(arr[i].date.day, arr[i].date.month,
arr[i].date.year) == min) {
for (j = i + 1; j < n; j++)
arr[j - 1] = arr[j];
n--;
i--;
}
}
}
}
return n;
}
int main() {
struct Grade arr[3] = {
{"Luc Manning", 10, {1, "Physics", 25}, {19, 1, 2020}},
{"Kaia Feeney", 8, {1, "Math", 25}, {19, 1, 2020}},
{"Luc Manning", 7, {2, "Linear Algebra", 10}, {11, 1, 2020}}};
int vel = digits_in_date(arr, 3);
int i;
for (i = 0; i < vel; i++)
printf("%s - %s\n", arr[i].namesurname, arr[i].subject.name_of_subject);
return 0;
}