Лекция 01 - Преговор, Линукс

Инсталация на Линукс

Работа с Линукс

Код от час

В клас

Задачите - https://docs.google.com/document/d/1b9GLjS-znRqyeDwlhdJlM40TGW-d7LCVXG26ft90-9o/edit?usp=sharing и https://docs.google.com/document/d/1XIWP8aGNed8XN5EKNBamEumDfiaFjJu676u1gAPz20U/edit?usp=sharing

#include <stdio.h>

unsigned int find_longest(char data[], int length) {
    int count = 1, max_count = 0;
    char last_seen;

    for(int i = 0; i <= length;i++){
      if(last_seen == data[i]) {
        count++;
      } else {
        last_seen = data[i];
        if(count > max_count) max_count = count;
        count = 1;
      }
    }

    return max_count;
}

int main() {
  printf("%d\n", find_longest("MERY", 4));
  printf("%d\n", find_longest("MMEERRYY", 8));
  printf("%d\n", find_longest("MEERRRYYYY", 10));
  printf("%d\n", find_longest("EEMRRRYYMM", 10));
/*
MERY => 1
MMEERRYY => 2
MEERRRYYYY => 4
EEMRRRYYMM=> 3*/

  return 0;
}
#include <string.h>

struct package_t {
  /*char* from;
  char* to;
  char* content;*/
  char from[16];
  char to[16];
  char content[256];
  unsigned int weight;
};

int validate(struct package_t* package) {
  if(
     package->from[0] == 0
  || package->to[0] == 0
  || package->weight > 10) {
    return 0;
  }

  for(int i =0; i<strlen(package->content); i++) {
    if(
         !(
               (package->content[i] >= 'a' && package->content[i] <= 'z')
            || (package->content[i] >= '0' && package->content[i] <= '9')
            || (package->content[i] == ' ')
          )
      ) {
        return 0;
      }
  }

  return 1;
}
#include <stdlib.h>

struct item_t {
  char* title;
  short important;
  short urgency;
};

struct list_t {
  struct list_t* next;
  struct list_t* prev;
  struct item_t* item;
};

void add(struct list_t* list, struct item_t* item) {
  if(list->item == NULL) {
    list->item = item;
    return;
  }

  while(list->next != NULL) {
    list = list->next;
  }

  list->next = malloc(sizeof(struct list_t));
  if(list->next == NULL) {
    return;
  }

  list->next->next = NULL;
  list->next->prev = list;

  list->next->item = item;
}

int main() {
  struct list_t l = {NULL, NULL, NULL};
  struct item_t i = {
    "asdf",
    1,
    1
  };
  add(&l, &i);
  return 0;
}