Лекция 04 - Упражнение

Код от часа - А клас

#include <stdio.h>
#include <string.h>

int verify_and_print_mac(char *mac) {
  /*for(int i=0; mac[i] != '\0'; i++) {
    if(i>17) return 0;
  }
  */
  if(strlen(mac) > 17) return 0;
}

int main() {
  printf("%d\n", verify_and_print_mac("0a:1b:2c:3d:4e:5f"));
  return 0;
}
#include <stdio.h>

struct monitor_t {
  char name[21];
  float diagonal;
  int score;
};

struct monitor_shop_t {
  struct monitor_t monitors[5];
  int count;
};

struct monitor_shop_t my_shop;
my_shop.monitors[2].diagonal;

struct monitor_t read_monitor() {
  struct monitor_t new_monitor;

  fgets(new_monitor.name, 20, stdin);
  scanf("%f %d", &new_monitor.diagonal, &new_monitor.score);

  return new_monitor;
}
/*
struct monitor_t monitors[5]
int              arr     [5]

struct monitor_t m = monitors[0]
int              n = arr     [0]
*/
struct monitor_t choose_monitor(struct monitor_t monitors[5], float diagonal) {
  struct monitor_t result = monitors[0];

  for(int i=0; i < 5; i++) {
    struct monitor_t curr = monitors[i];
    if(curr.diagonal == diagonal &&
       curr.score > result.score) {
      result = curr;
    }
  }

  return result;
}

int main() {
  struct monitor_t monitor = read_monitor();

  printf("%s %f %d\n", monitor.name, monitor.diagonal, monitor.score);
  return 0;
}

Код от часа - Б клас

#include <stdio.h>
#include <string.h>

int main() {
  char str[26];

  fgets(str, 25, stdin);
  strcpy
  strcat
  strstr
  strtok
  printf("%d %s\n", strlen(str), str);
  return 0;
}
#include <stdio.h>

struct marks_t {
  float marks[5];
  int count;
};// class_a, class_b = {{2,2,2,2,2}, 5}, class_v = {{2,2,2,2,2}, 5};
//int a, b = 5, c;

struct classes_t {
  struct marks_t class_a;
  struct marks_t class_b;
  struct marks_t class_v;
};

int sum(int a, int b);

int main() {
  //float m[] = {2,2,2,2,2};
  struct marks_t class_b = {{2,2,2,2,2}, 5};
  //class_b.marks = {2,2,2,2,2};
  /*for(int i=0; i< 5; i++) {
    class_b.marks[i] = 2;
  }
  class_b.count = 5;
  */

  for(int i=0; i<class_b.count; i++) {
    printf("%d %f\n", i, class_b.marks[i]);
  }
/*
  struct classes_t school = {
    {{2,2,2,2,2}, 5},
    {{2,2,2,2,2,2,2,2}, 8},
    {{2,2,2,3}, 4}
  };
  school.class_a.marks[2] = 5;
  */
  sum(4,5);

  return 0;
}


int sum(int a, int b) {
  return a + b;
}

Код от часа - В клас

#include <stdio.h>
#include <stdlib.h>

int main() {

//  char str[250];
  char* str = malloc(sizeof(char) * 250);
  fgets(str, 25, stdin);

  printf("str= %s\n", str);

  return 0;
}
struct player_t {
  char name[10];
  float height;
};

struct team_t {
  char name[100];

  struct player_t players[11];
  int             players[11];
};


int main() {
  return 0;
}
struct time_t {
  short hour;
  short minutes;
};

int is_before(struct time_t t1, struct time_t t2) {
  return time1.hour < time2.hour ||
    (time1.hour == time2.hour && time1.minutes < time2.minutes)
}

int is_lunch_break(struct time_t time) {
  return time.hour >= 12 && time.hour <=14 &&
    time.minutes >=15 && time.minutes <=23;
}
struct card_t {
  int type;
  char color;
};

struct card_t fight(struct card_t c1, struct card_t c2) {
  if(c1.type > c2.type) return c1;
  else if(c2.type > c1.type) return c2;
  else {
    if(c1.color > c2.color) return c1;
    else if(c2.color > c1.color) return c2;
    else return c1;
  }
}

int main() {
  struct card_t c1 = {2, 'C'};
  struct card_t  c2 = {3, 'C'};
  struct card_t res = fight(c1, c2);
  printf("%d %c\n", res.type, res.color);
  return 0;
}