Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #define STR_LEN 100
- #define ITEM_LEN 50
- #define INF (int)1e3
- //structures and types.................................
- typedef struct professor_struct{
- char name[STR_LEN];
- char surname[STR_LEN];
- char lectures[ITEM_LEN][STR_LEN];
- int lect_count;
- int first_course_taken;
- int second_course_taken;
- }professor;
- typedef struct TA_struct{
- char name[STR_LEN];
- char surname[STR_LEN];
- char lectures[ITEM_LEN][STR_LEN];
- int lect_count;
- int course_taken[4];
- }TA;
- typedef struct lecture_struct{
- char name[STR_LEN];
- int lab_n;
- int stud_n;
- int taken_by_prof;
- int taken_by_TA[ITEM_LEN];
- }lecture;
- typedef struct student_struct{
- char name[STR_LEN];
- char surname[STR_LEN];
- char ID[5+1];
- char lectures[ITEM_LEN][STR_LEN];
- int lect_count;
- }student;
- //global variables.....................................
- FILE *inp;
- lecture glob_lectures[ITEM_LEN];
- professor glob_professors[ITEM_LEN];
- TA glob_TAs[ITEM_LEN];
- student glob_students[ITEM_LEN];
- int if_the_lecture_then_student[ITEM_LEN];
- int if_not_lecture_then_student[ITEM_LEN];
- int ANSWER = INF;
- int PRINT_OUTPUT = 0;
- int GLC = 0;
- int GPC = 0;
- int GTAC = 0;
- int GSC = 0;
- //tools................................................
- void read_string_token(char* where){
- int token_len = 0;
- char c;
- while ( isalpha (c = fgetc(inp)) ){
- where[token_len] = c;
- token_len++;
- }
- ungetc(c ,inp);
- if (strcmp("",where) == 0){
- where[0] = '\0'; //incorrect output
- token_len = 1;
- }
- where[token_len] = '\0';
- }
- int read_int_token(){
- int invalid_int = ( 1<<(8*sizeof(int) - 1) ); //the most negative int
- int ans = invalid_int;
- int sign = 1;
- char c;
- ( (c = fgetc(inp)) == '-' ) ? sign = -1: ungetc(c, inp);
- while ( isdigit ( c = fgetc(inp)) ){
- if (ans == invalid_int && c != '0') ans = 0;
- else if (ans == invalid_int && c == '0') return invalid_int;
- ans = ans*10 + (c-'0');
- }
- ungetc(c ,inp);
- ans = ans * sign;
- return ans;
- }
- char *read_ID(){
- char *token = (char*) calloc(6, sizeof(char) );
- int token_len = 0;
- char c;
- do {
- c = fgetc(inp);
- if ( !(isdigit(c) || isalpha(c)) ) break;
- token[token_len++] = c;
- }while(1);
- ungetc(c ,inp);
- if ( token_len != 5 ){
- token[0] = '-'; //incorrect output
- token_len = 1;
- }
- token[token_len] = '\0';
- return token;
- }
- //procedures for getting data.........................
- int get_info(){
- GLC = 0;
- while (1){ // reading lectures
- int temp_int;
- read_string_token(glob_lectures[GLC].name);
- if (strcmp(glob_lectures[GLC].name , "") == 0 ) return -1;
- if (strcmp(glob_lectures[GLC].name, "P") == 0){
- if (fgetc(inp)!='\n') return -1;
- break;
- }
- if (strcmp(glob_lectures[GLC].name, "P") == 0 ||
- strcmp(glob_lectures[GLC].name, "T") == 0 ||
- strcmp(glob_lectures[GLC].name, "S") == 0){
- return -1;
- }
- if (fgetc(inp) != ' '){ return -1; }
- temp_int = read_int_token();
- if (temp_int<=0) return -1;
- glob_lectures[GLC].lab_n = temp_int;
- if (fgetc(inp) != ' '){ return -1; }
- temp_int = read_int_token();
- if (temp_int<=0) return -1;
- glob_lectures[GLC].stud_n = temp_int;
- if (fgetc(inp) != '\n'){ return -1; }
- //some initializations
- glob_lectures[GLC].taken_by_prof = -1;
- for (int i = 0; i < glob_lectures[GLC].lab_n; i++) {
- glob_lectures[GLC].taken_by_TA[i] = (-1);
- //printf("%d ", glob_lectures[GLC].taken_by_TA[i]);
- }
- GLC++;
- }
- GPC = 0;
- while (1){ //reading professors
- int temp_int;
- read_string_token(glob_professors[GPC].name);
- if (strcmp(glob_professors[GPC].name, "T") == 0){
- if (fgetc(inp)!='\n') return -1;
- break;
- }
- if (strcmp(glob_professors[GPC].name, "P") == 0 ||
- strcmp(glob_professors[GPC].name, "T") == 0 ||
- strcmp(glob_professors[GPC].name, "S") == 0){
- return -1;
- }
- if (strcmp(glob_professors[GPC].name, "") == 0) return -1;
- if (fgetc(inp) != ' '){ return -1; }
- read_string_token(glob_professors[GPC].surname);
- if (strcmp(glob_professors[GPC].surname, "") == 0) return -1;
- if (strcmp(glob_professors[GPC].surname, "T") == 0){
- return -1;
- }
- if (strcmp(glob_professors[GPC].surname, "P") == 0 ||
- strcmp(glob_professors[GPC].surname, "T") == 0 ||
- strcmp(glob_professors[GPC].surname, "S") == 0){
- return -1;
- }
- glob_professors[GPC].lect_count = 0;
- do {
- char new = fgetc(inp);
- if (new != ' ' && new!= '\n'){ return -1; }
- if (new == '\n') break;
- int current_count = glob_professors[GPC].lect_count++;
- read_string_token(glob_professors[GPC].lectures[current_count]);
- if (strcmp(glob_professors[GPC].lectures[current_count], "P") == 0 ||
- strcmp(glob_professors[GPC].lectures[current_count], "T") == 0 ||
- strcmp(glob_professors[GPC].lectures[current_count], "S") == 0){
- return -1;
- }
- if (strcmp(glob_professors[GPC].lectures[current_count], "") == 0) return -1;
- if ( strcmp(glob_professors[GPC].lectures[current_count], "0") == 0 ){
- return -1;
- }
- }while(1);
- //some initialization
- glob_professors[GPC].first_course_taken = -1;
- glob_professors[GPC].second_course_taken = -1;
- GPC++;
- }
- GTAC = 0; //reading TAs
- while (1){
- int temp_int;
- read_string_token(glob_TAs[GTAC].name);
- if (strcmp(glob_TAs[GTAC].name, "") == 0) return -1;
- if (strcmp(glob_TAs[GTAC].name, "S") == 0){
- char c;
- if ( (c = fgetc(inp))!='\n' && c != EOF) return -1;
- if (c == EOF) return 0;
- break;
- }
- if (strcmp(glob_TAs[GTAC].name, "P") == 0 ||
- strcmp(glob_TAs[GTAC].name, "T") == 0 ||
- strcmp(glob_TAs[GTAC].name, "S") == 0){
- return -1;
- }
- if (fgetc(inp) != ' '){ return -1; }
- read_string_token(glob_TAs[GTAC].surname);
- if (strcmp(glob_TAs[GTAC].surname, "") == 0) return -1;
- if (strcmp(glob_TAs[GTAC].surname, "S") == 0){
- return -1;
- }
- if (strcmp(glob_TAs[GTAC].surname, "P") == 0 ||
- strcmp(glob_TAs[GTAC].surname, "T") == 0 ||
- strcmp(glob_TAs[GTAC].surname, "S") == 0){
- return -1;
- }
- if (fgetc(inp) != ' '){ return -1; }
- glob_TAs[GTAC].lect_count = 0;
- do {
- int current_count = glob_TAs[GTAC].lect_count++;
- read_string_token(glob_TAs[GTAC].lectures[current_count]);
- if (strcmp(glob_TAs[GTAC].lectures[current_count], "P") == 0 ||
- strcmp(glob_TAs[GTAC].lectures[current_count], "T") == 0 ||
- strcmp(glob_TAs[GTAC].lectures[current_count], "S") == 0){
- return -1;
- }
- //printf ("(%s)", glob_TAs[GTAC].lectures[current_count]);
- char new = fgetc(inp);
- if (new != ' ' && new!= '\n'){ return -1; }
- if (new == '\n') break;
- if (strcmp(glob_TAs[GTAC].lectures[current_count], "") == 0) return -1;
- if ( strcmp(glob_TAs[GTAC].lectures[current_count], "0") == 0 ){
- return -1;
- }
- }while(1);
- //some initialization
- for (int i = 0; i < 4; i++){
- glob_TAs[GTAC].course_taken[i] = -1;
- }
- GTAC++;
- }
- GSC = 0; //reading students
- while (1){
- int temp_int;
- read_string_token(glob_students[GSC].name);
- if (strcmp(glob_students[GSC].name, "P") == 0 ||
- strcmp(glob_students[GSC].name, "T") == 0 ||
- strcmp(glob_students[GSC].name, "S") == 0){
- return -1;
- }
- if (strcmp(glob_students[GSC].name, "") == 0) return -1;
- if (fgetc(inp) != ' '){ return -1; }
- read_string_token(glob_students[GSC].surname);
- if (strcmp(glob_students[GSC].surname, "P") == 0 ||
- strcmp(glob_students[GSC].surname, "T") == 0 ||
- strcmp(glob_students[GSC].surname, "S") == 0){
- return -1;
- }
- if (strcmp(glob_students[GSC].surname, "") == 0) return -1;
- if (fgetc(inp) != ' '){ return -1; }
- char *temp_str;
- temp_str = read_ID();
- if (strcmp(temp_str, "") == 0) return -1;
- if(strcmp (temp_str, "-") == 0) return -1;
- strcpy(glob_students[GSC].ID,temp_str);
- glob_students[GSC].lect_count = 0;
- do {
- char new = fgetc(inp);
- if (new != ' ' && new!= '\n' && new!=EOF){ return -1; }
- if (new == '\n') break;
- if (new == EOF) {GSC++; return 0;}
- int current_count = glob_students[GSC].lect_count++;
- read_string_token(glob_students[GSC].lectures[current_count]);
- if (strcmp(glob_students[GSC].lectures[current_count], "P") == 0 ||
- strcmp(glob_students[GSC].lectures[current_count], "T") == 0 ||
- strcmp(glob_students[GSC].lectures[current_count], "S") == 0){
- return -1;
- }
- if (strcmp(glob_students[GSC].lectures[current_count], "") == 0) return -1;
- if ( strcmp(glob_students[GSC].lectures[current_count], "0") == 0 ){
- return -1;
- }
- }while(1);
- //some initializations
- GSC++;
- }
- }
- //..........................................................................................
- void assign_prof(int prof, int lecture){ //assign prof to lecture
- if (glob_professors[prof].first_course_taken == -1){
- glob_professors[prof].first_course_taken = lecture;
- glob_lectures[lecture].taken_by_prof = prof;
- }
- else if (glob_professors[prof].second_course_taken == -1){
- glob_professors[prof].second_course_taken = lecture;
- glob_lectures[lecture].taken_by_prof = prof;
- }
- else{
- printf("INVALID_CALL_TO_ASSIGN_PROF");
- }
- }
- void deassign_prof(int prof, int lecture){ //deassign prof from lecture
- if (glob_professors[prof].second_course_taken == lecture){
- glob_professors[prof].second_course_taken = -1;
- glob_lectures[lecture].taken_by_prof = -1;
- }
- else if (glob_professors[prof].first_course_taken == lecture){
- glob_professors[prof].first_course_taken = -1;
- glob_lectures[lecture].taken_by_prof = -1;
- }
- else{
- printf("INVALID_CALL_TO_DEASSIGN_PROF");
- }
- }
- int prof_trained(int prof, int lect){ //is prof trained or not
- int ans = 0;
- for (int i = 0; i < glob_professors[prof].lect_count; i++){
- if ( strcmp(glob_professors[prof].lectures[i], glob_lectures[lect].name) == 0 ){
- ans = 1;
- }
- }
- return ans;
- }
- int prof_can_be_assigned(int prof, int lecture){ // is prof free
- if (glob_professors[prof].first_course_taken==-1 && glob_professors[prof].second_course_taken==-1){
- return 1;
- }
- else if (glob_professors[prof].first_course_taken!=-1 && glob_professors[prof].second_course_taken==-1){
- if (prof_trained(prof, lecture)==1 && prof_trained(prof, glob_professors[prof].first_course_taken)==1){
- return 1;
- }
- }
- return 0;
- }
- int TA_can_be_assigned(int TA, int lect){ // can TA be assigned to lect?
- int ans = 0;
- int trained = 0;
- for (int i = 0; i < glob_TAs[TA].lect_count; i++){
- if ( strcmp(glob_TAs[TA].lectures[i], glob_lectures[lect].name) == 0){
- trained = 1;
- }
- }
- if (trained==1){
- for (int i = 0; i < glob_lectures[lect].lab_n; i++){
- if (glob_lectures[lect].taken_by_TA[i] == -1){
- for (int j = 0; j < 4; j++){
- if (glob_TAs[TA].course_taken[j] == -1){
- ans = 1;
- }
- }
- }
- }
- }
- return ans;
- }
- void assign_TA(int TA,int lect){ //assign TA to lect
- for (int i = 0; i < glob_lectures[lect].lab_n; i++){
- if (glob_lectures[lect].taken_by_TA[i] == -1){
- for (int j = 0; j < 4; j++){
- if (glob_TAs[TA].course_taken[j] == -1){
- glob_lectures[lect].taken_by_TA[i] = TA;
- glob_TAs[TA].course_taken[j] = lect;
- return;
- }
- }
- }
- }
- printf("ERROR_IN_ASSIGN_TA");
- }
- void deassign_TA(int TA, int lect){ //deassign TA from lect
- for (int i = 0; i < glob_lectures[lect].lab_n ; i++){
- if (glob_lectures[lect].taken_by_TA[i] == TA){
- for (int j = 0; j < 4 ; j++){
- if (glob_TAs[TA].course_taken[j] == lect){
- glob_lectures[lect].taken_by_TA[i] = -1;
- glob_TAs[TA].course_taken[j] = -1;
- return;
- }
- }
- }
- }
- printf("ERROR_IN_DEASSIGN__TA");
- }
- int professor_sum(int prof){ //count badness points on professor
- int ans = 0;
- if (glob_professors[prof].first_course_taken != -1 && glob_professors[prof].second_course_taken != -1){
- int OK = 0;
- for (int j = 0; j < glob_professors[prof].lect_count; j++){
- for (int z = 0; z < glob_professors[prof].lect_count; z++){
- int first = glob_professors[prof].first_course_taken;
- int second = glob_professors[prof].second_course_taken;
- if ( strcmp(glob_professors[prof].lectures[j], glob_lectures[first].name) == 0 &&
- strcmp(glob_professors[prof].lectures[z], glob_lectures[second].name) == 0){
- OK = 1;
- }
- }
- }
- if (OK == 0) ans += INF;
- }
- if (glob_professors[prof].first_course_taken == -1 && glob_professors[prof].second_course_taken != -1){
- ans+=5;
- }
- if (glob_professors[prof].first_course_taken != -1 && glob_professors[prof].second_course_taken == -1){
- ans+=5;
- }
- if (glob_professors[prof].first_course_taken == -1 && glob_professors[prof].second_course_taken == -1){
- ans+=10;
- }
- return ans;
- }
- int TA_sum(int TA){ //count badness points on TA
- int ans = 0;
- for (int course = 0; course < 4; course++){
- if ( glob_TAs[TA].course_taken[course] == -1 ){
- ans+=2;
- }
- else{
- char lecture_name[STR_LEN];
- strcpy(lecture_name, glob_lectures[glob_TAs[TA].course_taken[course]].name);
- int OK = 0;
- for (int i = 0; i < glob_TAs[TA].lect_count; i++){
- if (strcmp(lecture_name, glob_TAs[TA].lectures[i]) == 0){
- OK = 1;
- }
- }
- if (OK == 0){
- ans+=INF;
- }
- }
- }
- return ans;
- }
- int lecture_sum(int lect){ //count badness points on lect
- int ans = 0;
- int TA_OK = 1;
- for (int j = 0; j < glob_lectures[lect].lab_n; j++) {
- if (glob_lectures[lect].taken_by_TA[j] == -1) {
- TA_OK = 0;
- }
- }
- if ( TA_OK == 0 || glob_lectures[lect].taken_by_prof == -1){
- int no_TA = 1;
- for (int j = 0; j < glob_lectures[lect].lab_n; j++) {
- if (glob_lectures[lect].taken_by_TA[j] != -1) {
- no_TA = 0;
- }
- }
- if (no_TA == 1 && glob_lectures[lect].taken_by_prof == -1){
- ans+=20;
- }
- else{
- ans+=(int) INF;
- }
- }
- return ans;
- }
- int stud_sum(){ //count badness points on students
- int ans = 0;
- for (int j = 0; j < GLC; j++){
- if (lecture_sum(j) == 0){
- ans += if_the_lecture_then_student[j];
- }
- else if ( lecture_sum(j) == 20 ){
- ans+= if_not_lecture_then_student[j];
- }
- }
- return ans;
- }
- void count_students_and_lectures(){ //the idea is to count beforehand
- for (int i = 0; i < GLC; i++){ //how many badness pints do we get
- if_the_lecture_then_student[i] = 0; //if course i is run or not run
- }
- for (int i = 0 ; i < GSC; i++){
- for (int j = 0; j < glob_students[i].lect_count; j++){
- for (int z = 0; z < GLC; z++){
- if (strcmp(glob_lectures[z].name, glob_students[i].lectures[j]) == 0){
- if_not_lecture_then_student[z]++;
- }
- }
- }
- }
- for (int i = 0; i < GLC; i++){
- if (if_not_lecture_then_student[i] > glob_lectures[i].stud_n ){
- if_the_lecture_then_student[i] = if_not_lecture_then_student[i] - glob_lectures[i].stud_n;
- }
- else {
- if_the_lecture_then_student[i] = 0;
- }
- }
- }
- int count_temp = 0;
- void count_badness_points_and_print_answer(){
- int sum = 0;
- for (int lecture = 0; lecture < GLC; lecture++){
- sum += lecture_sum(lecture);
- }
- for (int prof = 0; prof < GPC; prof++){
- sum += professor_sum(prof);
- }
- for (int TA = 0; TA < GTAC; TA++){
- sum += TA_sum(TA);
- }
- sum += stud_sum();
- if (sum < ANSWER){
- ANSWER = sum;
- }
- if (sum == ANSWER && PRINT_OUTPUT == 1){
- PRINT_OUTPUT = 0;
- for (int lect = 0; lect < GLC; lect++){
- int TA_ok = 1;
- for (int j = 0; j < glob_lectures[lect].lab_n; j++){
- if (glob_lectures[lect].taken_by_TA[j] == -1){
- TA_ok = 0;
- }
- }
- if (!(TA_ok == 1 && glob_lectures[lect].taken_by_prof != -1)) continue;
- printf("%s\n", glob_lectures[lect].name );
- int professor = glob_lectures[lect].taken_by_prof;
- printf("%s",glob_professors[professor].name);
- printf(" ");
- printf("%s\n",glob_professors[professor].surname);
- for (int lab = 0; lab < glob_lectures[lect].lab_n; lab++){
- int TA = glob_lectures[lect].taken_by_TA[lab];
- printf("%s", glob_TAs[TA].name);
- printf(" ");
- printf("%s\n",glob_TAs[TA].surname);
- }
- int counter_of_stud = 0;
- int student = 0;
- while (counter_of_stud < glob_lectures[lect].stud_n && student < GSC){
- for (int stud_course = 0; stud_course < glob_students[student].lect_count; stud_course++){
- char course_name [STR_LEN];
- strcpy(course_name, glob_students[student].lectures[stud_course]);
- if (strcmp(course_name, glob_lectures[lect].name) == 0){
- printf("%s", glob_students[student].name);
- printf(" ");
- printf("%s", glob_students[student].surname);
- printf(" ");
- printf("%s\n",glob_students[student].ID);
- counter_of_stud++;
- }
- }
- student++;
- }
- printf("\n");
- }
- for (int lect = 0; lect < GLC; lect++){
- int TA_ok = 1;
- for (int j = 0; j < glob_lectures[lect].lab_n; j++){
- if (glob_lectures[lect].taken_by_TA[j] == -1){
- TA_ok = 0;
- }
- }
- if (TA_ok == 0 || glob_lectures[lect].taken_by_prof == -1){
- printf("%s", glob_lectures[lect].name);
- printf(" cannot be run.\n");
- }
- }
- for (int prof = 0; prof < GPC; prof++){
- if (glob_professors[prof].first_course_taken == -1 && glob_professors[prof].second_course_taken == -1) {
- printf("%s", glob_professors[prof].name);
- printf(" ");
- printf("%s", glob_professors[prof].surname);
- printf(" is unassigned.\n");
- }
- else if( glob_professors[prof].first_course_taken != -1 && glob_professors[prof].second_course_taken == -1){
- if (prof_trained(prof, glob_professors[prof].first_course_taken) == 0) {
- printf("%s", glob_professors[prof].name);
- printf(" ");
- printf("%s", glob_professors[prof].surname);
- printf(" is not trained for ");
- printf("%s", glob_lectures[glob_professors[prof].first_course_taken].name);
- printf(".\n");
- }
- else{
- printf("%s", glob_professors[prof].name);
- printf(" ");
- printf("%s", glob_professors[prof].surname);
- printf(" is lacking class.\n");
- }
- }
- }
- for (int TA = 0; TA < GTAC; TA++){
- int count = 0;
- for (int i = 0; i < 4; i++){
- if (glob_TAs[TA].course_taken[i] == -1){
- count++;
- }
- }
- if (count > 0) {
- printf("%s", glob_TAs[TA].name);
- printf(" ");
- printf("%s", glob_TAs[TA].surname);
- printf(" is lacking ");
- printf("%d", count);
- printf(" lab(s).\n");
- }
- }
- for (int lect = 0; lect < GLC; lect++){
- int TA_ok = 1;
- for (int j = 0; j < glob_lectures[lect].lab_n; j++){
- if (glob_lectures[lect].taken_by_TA[j] == -1){
- TA_ok = 0;
- }
- }
- if (TA_ok == 0 || glob_lectures[lect].taken_by_prof == -1){
- for (int student = 0; student < GSC; student++){
- for (int course = 0; course < glob_students[student].lect_count; course++){
- char course_name[STR_LEN];
- strcpy(course_name, glob_students[student].lectures[course]);
- if (strcmp(course_name, glob_lectures[lect].name) == 0){
- printf("%s", glob_students[student].name);
- printf(" ");
- printf("%s", glob_students[student].surname);
- printf(" is lacking ");
- printf("%s\n", course_name);
- }
- }
- }
- }
- else{
- int P = if_the_lecture_then_student[lect];
- int counter = P;
- if ( P > 0 ){
- for (int student = GSC-1; student >= 0 && counter > 0; student--){
- for (int course = 0; course < glob_students[student].lect_count; course++){
- char course_name[STR_LEN];
- strcpy(course_name, glob_students[student].lectures[course]);
- if (strcmp(course_name, glob_lectures[lect].name) == 0){
- printf("%s", glob_students[student].name);
- printf(" ");
- printf("%s", glob_students[student].surname);
- printf(" is lacking ");
- printf("%s\n", course_name);
- counter--;
- }
- }
- }
- }
- }
- }
- printf("Total score is %d.\n", ANSWER);
- }
- }
- void brute_TAs(int number_of_lecture){
- for (int TA = 0; TA < GTAC; TA++){
- if ( TA_can_be_assigned(TA, number_of_lecture) == 1){
- assign_TA(TA, number_of_lecture);
- brute_TAs(number_of_lecture);
- deassign_TA(TA, number_of_lecture);
- }
- }
- if (number_of_lecture+1 < GLC){
- brute_TAs(number_of_lecture+1);
- }
- else{
- count_badness_points_and_print_answer();
- }
- }
- void brute_professors(int number_of_lect) {
- for (int prof = 0; prof < GPC; prof++) {
- if (prof_can_be_assigned(prof, number_of_lect) == 1) {
- assign_prof(prof, number_of_lect);
- if (number_of_lect + 1 < GLC) {
- brute_professors(number_of_lect + 1);
- } else {
- brute_TAs(0);
- }
- deassign_prof(prof, number_of_lect);
- }
- }
- //did not assign professor
- if (number_of_lect + 1 < GLC) {
- brute_professors(number_of_lect + 1);
- } else {
- brute_TAs(0);
- }
- }
- int solve(){
- brute_professors(0);
- PRINT_OUTPUT = 1;
- brute_professors(0);
- return 0;
- }
- int input_ok(){
- for (int i = 0; i < GPC; i++){
- for (int j = 0; j < glob_professors[i].lect_count; j++){
- int lect_is_ok = 0;
- for (int z = 0; z < GLC; z++){
- if (strcmp(glob_professors[i].lectures[j], glob_lectures[z].name) == 0){
- lect_is_ok = 1;
- }
- }
- if (lect_is_ok == 0){
- return 0;
- }
- }
- }
- for (int i = 0; i < GTAC; i++){
- for (int j = 0; j < glob_TAs[i].lect_count; j++){
- int lect_is_ok = 0;
- for (int z = 0; z < GLC; z++){
- if (strcmp(glob_TAs[i].lectures[j], glob_lectures[z].name) == 0){
- lect_is_ok = 1;
- }
- }
- if (lect_is_ok == 0){
- return 0;
- }
- }
- }
- for (int i = 0; i < GSC; i++){
- for (int j = 0; j < glob_students[i].lect_count; j++){
- int lect_is_ok = 0;
- for (int z = 0; z < GLC; z++){
- if (strcmp(glob_students[i].lectures[j], glob_lectures[z].name) == 0){
- lect_is_ok = 1;
- }
- }
- if (lect_is_ok == 0){
- return 0;
- }
- }
- }
- for (int i = 0; i < GLC; i++){
- for (int j = i+1; j < GLC; j++){
- if (strcmp(glob_lectures[i].name, glob_lectures[j].name)==0){
- return 0;
- }
- }
- }
- for (int i = 0; i < GPC; i++){
- for (int j = i+1; j < GPC; j++){
- if (strcmp(glob_professors[i].name, glob_professors[j].name)==0||
- strcmp(glob_professors[i].surname, glob_professors[j].surname)==0){
- return 0;
- }
- }
- }
- for (int i = 0; i < GTAC; i++){
- for (int j = i+1; j < GTAC; j++){
- if (strcmp(glob_TAs[i].name, glob_TAs[j].name)==0||
- strcmp(glob_TAs[i].surname, glob_TAs[j].surname)==0){
- return 0;
- }
- }
- }
- for (int i = 0; i < GSC; i++){
- for (int j = i+1; j < GSC; j++) {
- if (strcmp(glob_students[i].ID, glob_students[j].ID) == 0 ) {
- return 0;
- }
- }
- }
- for (int i = 0; i < GPC; i++){
- if (glob_professors[i].lect_count == 0){
- return 0;
- }
- }
- for (int i = 0; i < GTAC; i++){
- if (glob_TAs[i].lect_count == 0){
- return 0;
- }
- }
- for (int i = 0; i < GSC; i++){
- if (glob_students[i].lect_count == 0){
- return 0;
- }
- }
- return 1;
- }
- //main................................................
- int main(){
- //inp = fopen("input.txt", "r");
- inp = stdin;
- if ( get_info() == -1) {
- printf("Invalid input.");
- return 0;
- }
- if (input_ok() == 0) {
- printf("Invalid input.");
- return 0;
- }
- count_students_and_lectures();
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement