commit 24ee0f2d8a80f0bdbe4a05972e74bfd955bcbc91 Author: Denis NutÌŠiu Date: Mon Apr 11 20:00:29 2016 +0300 Initial commit diff --git a/lab1/a.out b/lab1/a.out new file mode 100755 index 0000000..d9732c4 Binary files /dev/null and b/lab1/a.out differ diff --git a/lab1/lab1.c b/lab1/lab1.c new file mode 100644 index 0000000..29ac2e7 --- /dev/null +++ b/lab1/lab1.c @@ -0,0 +1,89 @@ +#include +#include +#include + +int isbn13(char * isbn) { + int sum = 0; + int n = 13; + for (int i = 0; i < n - 1; i++) { + if ( (i + 1) % 2 == 0 ) { + sum += 3 * (isbn[i] - '0'); + } else { + sum += isbn[i] - '0'; + } + } + if ( 10 - ( sum % 10) == isbn[n - 1] - '0' ) { + return 1; + } + return 0; +} + +char * conv_isbn13(char * isbn) { + char * new = malloc(13); + int n = 10; + new[0] = '9'; + new[1] = '7'; + new[2] = '8'; + for (int i = 0; i < n; i++) { + new[i+3] = isbn[i]; + } + return new; + new[13] = '\0'; +} + +int isbn10(char * isbn) { + int sum = 0; + for (int i = 0; i < 9; i++) { + sum += (i + 1) * (isbn[i] - '0'); + } + + if ( ( sum % 11) == isbn[9] - '0' ) { + return 1; + } + return 0; +} + +char * conv_isbn10(char * isbn) { + char * new = malloc(10); + for (int i = 0; i < 9; i++) { + new[i] = isbn[i+3]; + } + new[10] = '\0'; + return new; +} + +void guess2(int l, int h); + +void guessnum() { + printf("Think of a number between 0 and 100\n"); + guess2(0, 100); +} + +void guess2(int l, int h) { + int n = 0; + int fitty = (l + h) / 2 ; + int guess; + int guesst; + printf("IS your number %d?\n", fitty); + scanf("%d", &guesst); + if (guesst == 1) { + printf("Your number is %d\n", fitty); + exit(0); + } + while ( fitty != n ) { + printf("IS you number greather than %d\n", fitty); + scanf("%d", &guess); + if (guess == 1) { + guess2(fitty, h); + } else { + guess2(l, fitty); + } + } +} + +int main(int argc, char const *argv[]) { + guessnum(); + // printf("%s\n", conv_isbn10("9781435704572")); + // printf("%s\n", conv_isbn13("0521396549")); + return 0; +} diff --git a/lab2/libstr.a b/lab2/libstr.a new file mode 100644 index 0000000..0a19594 Binary files /dev/null and b/lab2/libstr.a differ diff --git a/lab2/main.c b/lab2/main.c new file mode 100644 index 0000000..3a5ab49 --- /dev/null +++ b/lab2/main.c @@ -0,0 +1,21 @@ +#include +#include +#include "str.h" + +int main(void) { + printf("%d\n", my_strcmp("abc", "abc")); + printf("%d\n", my_strcmp("adc", "abc")); + printf("%d\n", my_strcmp("abc", "adc")); + printf("%d\n", my_strcmp("abcd", "abc")); + printf("%d\n", my_strcmp("abc", "abcd")); + + char * dest = malloc(12); + char * dest2 = malloc(6); + char * src = "Ana are mere."; + my_strcpy(dest, src); + my_strncpy(dest2, src, 5); + + printf("%s\n", dest); + printf("%s\n", dest2); + return 0; +} diff --git a/lab2/makefile b/lab2/makefile new file mode 100644 index 0000000..553bb77 --- /dev/null +++ b/lab2/makefile @@ -0,0 +1,12 @@ +CC = gcc +TARGET = my_string +CFLAGS = -Wall -O3 +all: $(TARGET) + +$(TARGET): + $(CC) $(CFLAGS) -c str.c + ar rcs libstr.a str.o + $(CC) $(CFLAGS) main.c -o $(TARGET).x -L. -lstr + +clean: + $(RM) $(TARGET).x diff --git a/lab2/my_string.x b/lab2/my_string.x new file mode 100755 index 0000000..87a3942 Binary files /dev/null and b/lab2/my_string.x differ diff --git a/lab2/str.c b/lab2/str.c new file mode 100644 index 0000000..176557a --- /dev/null +++ b/lab2/str.c @@ -0,0 +1,32 @@ +#include + +int my_strcmp(char * one, char * two) { + if ( strlen(one) > strlen(two) ) { + return 1; + } else if ( strlen(one) < strlen(two) ) { + return -1; + } + + for (int i = 0; one[i]; i++) { + if ( one[i] > two[i] ) { + return 1; + } else if ( one[i] < two[i] ) { + return -1; + } + } + return 0; +} + +char * my_strcpy(char * dest, char * source) { + int index = 0; + while ( (dest[index] = source[index]) ) { index++; }; + dest[index] = '\0'; + return dest; +} + +char * my_strncpy(char * dest, char * source, size_t len) { + int index = 0; + while ( (dest[index] = source[index]) && index < len ) { index++; }; + dest[len] = '\0'; + return dest; +} diff --git a/lab2/str.h b/lab2/str.h new file mode 100644 index 0000000..e02c587 --- /dev/null +++ b/lab2/str.h @@ -0,0 +1,10 @@ +#include + +#ifndef MY_STRING_H +#define MY_STRING_H + +int my_strcmp(char * one, char * two); +char my_strcpy(char * dest, char * source); +char my_strncpy(char * dest, char * source, size_t len); + +#endif diff --git a/lab2/str.o b/lab2/str.o new file mode 100644 index 0000000..4b9d138 Binary files /dev/null and b/lab2/str.o differ diff --git a/lab3/a b/lab3/a new file mode 100755 index 0000000..efcfee2 Binary files /dev/null and b/lab3/a differ diff --git a/lab3/a.cpp b/lab3/a.cpp new file mode 100644 index 0000000..3d5fa90 --- /dev/null +++ b/lab3/a.cpp @@ -0,0 +1,75 @@ +#include + +using namespace std; +class Person { + protected: + string name; + int age; + + public: + virtual void getdata() = 0; + virtual void putdata() = 0; +}; + +class Professor : public Person { + static int professors; + int publications; + int id; + public: + Professor() { + Professor::professors++; + } + ~Professor() { + Professor::professors--; + } + + virtual void getdata() { + cin >> Professor::name; + cin >> Professor::age; + cin >> Professor::publications; + Professor::id = professors; + } + virtual void putdata() { + cout << Professor::name << " " << Professor::age << " " + << Professor::publications << " " << Professor::id << endl; + } +}; + +int Professor::professors = 0; + +class Student : public Person { + static int students; + int marks[6]; + int id; + public: + Student() { + Student::students++; + } + ~Student() { + Student::students--; + } + + virtual void getdata() { + cin >> Student::name; + cin >> Student::age; + Student::id = Student::students; + int mark; + for (int i = 0; i < 6; i++) { + cin >> mark; + Student::marks[i] = mark; + } + } + virtual void putdata() { + cout << Student::name << " " << Student::age << " "; + for (int i = 0; i < 6; i++) { + cout << Student::marks[i] << " "; + } + cout << Student::id << endl; + } +}; + +int Student::students = 0; + +int main() { + return 0; +} diff --git a/lab3/a.out b/lab3/a.out new file mode 100755 index 0000000..1918d4f Binary files /dev/null and b/lab3/a.out differ diff --git a/lab3/b b/lab3/b new file mode 100755 index 0000000..bc700a9 Binary files /dev/null and b/lab3/b differ diff --git a/lab3/c b/lab3/c new file mode 100755 index 0000000..70cbc78 Binary files /dev/null and b/lab3/c differ diff --git a/lab3/d b/lab3/d new file mode 100755 index 0000000..5271511 Binary files /dev/null and b/lab3/d differ diff --git a/lab3/i.txt b/lab3/i.txt new file mode 100644 index 0000000..36b0984 --- /dev/null +++ b/lab3/i.txt @@ -0,0 +1,26 @@ +1 +20 +2 +XAN 9 +FIVE 5 +FIVEz 5 +RAD 8 +Raasputiin 10 +MARIONE 9 +FAULT_Zero 11 +THREE 3 +Rick 9 +Scary 9 +XAN1 9 +FIVE1 5 +FIVEz1 5 +RAD1 8 +Raasputiin1 10 +MARIONE1 9 +FAULT1 11 +THREE1 3 +Rick1 9 +Scary1 9 +3 +4 +5 diff --git a/lab3/lab3_1.c b/lab3/lab3_1.c new file mode 100644 index 0000000..f3daf5e --- /dev/null +++ b/lab3/lab3_1.c @@ -0,0 +1,35 @@ +#include +#include +#include + +typedef int (*comp)(const void *, const void *); + +int sorter(double * a, double * b) { + if ( *a > *b ) { + return 1; + } else if ( *a < *b ) { + return -1; + } else { + return 0; + } +} + +void populate_array(double * array, size_t size) { + srand(time(0)); + for (int i = 0; i < size; i++) { + array[i] = rand() % 101; + // printf("%f\n", array[i]); + } + qsort(array, size, sizeof(array[0]), (comp) sorter); +} + +void parr(double * arr, size_t size) { + for (int i = 0; i < size; i++) printf("%f\n", arr[i]); +} + +int main(void) { + double array[5]; + populate_array(array, 5); + parr(array, 5); + return 0; +} diff --git a/lab3/lab3_2.c b/lab3/lab3_2.c new file mode 100644 index 0000000..eb6cbf9 --- /dev/null +++ b/lab3/lab3_2.c @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include + +typedef struct Student_Tag { + int grade; + char name[41]; +} Student; + +int n = 0; +Student ** students; + +int sort_grade(const void * a, const void * b) { + Student ** aa = (Student **) a; + Student ** bb = (Student **) b; + return (*bb)->grade - (*aa)->grade; +} + +int sort_alpha(const void * a, const void * b) { + Student ** aa = (Student **)a; + Student ** bb = (Student **)b; + return strcmp((*aa)->name, (*bb)->name); +} + +void initialize_students(unsigned n) { + students = malloc(sizeof(Student*) * n); +} + +void fenter_student() { + if (n == 0) { + printf("\tN must be bigger than 0, did you gave an N?\n"); + return; + } else { + + for (int i = 0; i < n; i++) { + students[i] = malloc(sizeof(Student)); + printf("Enter student: FIRST NAME_LAST NAME, GRADE. MAX 40 CHARACTERS!\n"); + scanf("%40s %d", students[i]->name, &students[i]->grade); + printf("Student was added successfully.\n"); + printf("Name: %s\n", students[i]->name); + printf("Grade: %d\n", students[i]->grade); + } + } +} + +void fgive_n() { + printf("Type your N\n"); + scanf("%d", &n); +} + +void display(Student ** arr, int n) { + for (int i = 0; i < n; i++) { + printf("Student %s Grade %d\n", arr[i]->name, arr[i]->grade); + } +} + +int choice() { + enum { exit_program, give_n, enter_student, display_class_alpha, + display_class_grade, display_first_three }; + + int ch = 0; // In case of EOF, will exit. Hopefully. + scanf("%d", &ch); + + switch (ch) { + case exit_program: + printf("Exiting..\n"); + return 1; + break; + case give_n: + fgive_n(); + initialize_students(n); + break; + case enter_student: + fenter_student(); + break; + case display_class_alpha: + assert(n > 0); + printf("Display according to name\n"); + qsort(students, n, sizeof(Student *), sort_alpha); + display(students, n); + break; + case display_class_grade: + assert(n > 0); + printf("Display according to grades\n"); + qsort(students, n, sizeof(Student *), sort_grade); + display(students, n); + break; + case display_first_three: + assert(n > 0); + printf("Display first three according to grades\n"); + qsort(students, n, sizeof(Student *), sort_grade); + display(students, 3); + break; + default: + printf("\tInvalid choice\n"); + } + return 0; +} + +void display_menu() { + printf("\n"); + printf("0. Exit program\n"); + printf("1. Give N, number of students\n"); + printf("2. Enter the student\n"); + printf("3. Display class in alphabetic order\n"); + printf("4. Display class in creating a top based on grades\n"); + printf("5. Display the first three students according to their grades\n"); + printf("\n"); +} + +int main() { + int sgexit = 0; + while (!sgexit) { + display_menu(); + sgexit = choice(); + } + return 0; +} diff --git a/lab3/lab3_2b.c b/lab3/lab3_2b.c new file mode 100644 index 0000000..6a3fe8e --- /dev/null +++ b/lab3/lab3_2b.c @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include + +typedef int (*comp)(const void *, const void *); + +typedef struct Student_Tag { + int grade; + char name[41]; +} Student; + +int n = 0; +Student * students; + +int sort_grade(Student * a, Student * b) { + return b->grade - a->grade; +} +int sort_alpha(Student * a, Student * b) { + return strcmp(a->name, b->name); +} + +void initialize_students(unsigned n) { + students = malloc(sizeof(Student) * n); +} + +void fenter_student() { + if (n == 0) { + printf("\tN must be bigger than 0, did you gave an N?\n"); + return; + } else { + int index = 0; + for (int i = 0; i < n; i++) { + printf("Enter student: FIRST NAME_LAST NAME, GRADE. MAX 40 CHARACTERS!\n"); + scanf("%40s %d", (students + index)->name, &(students + index)->grade); + printf("Student was added successfully.\n"); + printf("Name: %s\n", (students + index)->name); + printf("Grade: %d\n", (students + index)->grade); + index += sizeof(Student); + } + } +} + +void fgive_n() { + printf("Type your N\n"); + scanf("%d", &n); +} + +void display(Student * arr, int n) { + for (int i = 0; i < n * sizeof(Student); i += sizeof(Student)) { + printf("Student %s Grade %d\n", arr[i].name, arr[i].grade); + } +} + +int choice() { + enum { exit_program, give_n, enter_student, display_class_alpha, + display_class_grade, display_first_three }; + int ch = 0; + scanf("%d", &ch); + switch (ch) { + case exit_program: + printf("Exiting..\n"); + return 1; + break; + case give_n: + fgive_n(); + initialize_students(n); + break; + case enter_student: + fenter_student(); + break; + case display_class_alpha: + assert(n > 0); + printf("Display according to name\n"); + qsort(students, n, sizeof(students[0]), (comp)sort_alpha); + display(students, n); + break; + case display_class_grade: + assert(n > 0); + // printf("%lu %lu \n", sizeof(students), sizeof(students[0]) ); + printf("Display according to grades\n"); + qsort(students, n, sizeof(students[0]), (comp)sort_grade); + display(students, n); + break; + case display_first_three: + assert(n > 0); + printf("Display first three according to grades\n"); + qsort(students, n, sizeof(students[0]), (comp)sort_grade); + display(students, 3); + break; + default: + printf("\tInvalid choice\n"); + } + return 0; +} + +void display_menu() { + printf("\n"); + printf("0. Exit program\n"); + printf("1. Give N, number of students\n"); + printf("2. Enter the student\n"); + printf("3. Display class in alphabetic order\n"); + printf("4. Display class in creating a top based on grades\n"); + printf("5. Display the first three students according to their grades\n"); + printf("\n"); +} + +int main() { + int sgexit = 0; + while (!sgexit) { + display_menu(); + sgexit = choice(); + } + return 0; +} diff --git a/lab3/lab3_3.c b/lab3/lab3_3.c new file mode 100644 index 0000000..12f70d6 --- /dev/null +++ b/lab3/lab3_3.c @@ -0,0 +1,35 @@ +#include +#include + +void guess2(int, int); +void guessnum() { + printf("Think of a number between 0 and 100\n"); + guess2(0, 100); +} + +void guess2(int l, int h) { + int n = 0; + int fitty = (l + h) / 2 ; + int guess; + int guesst; + printf("IS your number %d?\n", fitty); + scanf("%d", &guesst); + if (guesst == 1) { + printf("Your number is %d\n", fitty); + exit(0); + } + while ( fitty != n ) { + printf("IS you number greather than %d\n", fitty); + scanf("%d", &guess); + if (guess == 1) { + guess2(fitty, h); + } else { + guess2(l, fitty); + } + } +} + +int main(int argc, char const *argv[]) { + guessnum(); + return 0; +} diff --git a/lab3/lab3_4.c b/lab3/lab3_4.c new file mode 100644 index 0000000..40ab5f4 --- /dev/null +++ b/lab3/lab3_4.c @@ -0,0 +1,61 @@ +#include +#include + +int is_prime(int); + +int populate_array(int * array, size_t size) { + int index = 0; + for (int i = 1; i < size; i++) { + if ( is_prime(i) ) { + array[index++] = i; + } + } + return index; +} + +int is_present(int * array, size_t size, int number); + +void parr(int * array, size_t size, size_t numbers) { + for (int i = 1; i < numbers; i++) + printf("%d IS PRESENT: %d\n",i, is_present(array, size, i)); +} + +int is_prime(int number) { + for (int i = 2; i <= number/2; i++) { + if ( number % i == 0 ) { + return 0; + } + } + return 1; +} + +int _is_present(int * array, int number, int low, int high) { + int middle = ((high + low) / 2.0); + //printf("L: %d H: %d M: %d N: %d\n", low, high, middle, number); + if ( number > array[middle] ) { + return _is_present(array, number, middle, high); + } else if ( number < array[middle] ) { + return _is_present(array, number, low, middle); + } else if ( number == array[middle] ) { + return 1; + } else { + return 0; + } +} + +int is_present(int * array, size_t size, int number) { + if ( is_prime(number) ) { + return _is_present(array, number, 0, size); + } else { + return 0; + } +} + +int main(void) { + int primes[100]; + int real_primes = populate_array(primes, 100); + //parr(primes, real_primes, 100); + printf("%d\n", is_present(primes, real_primes, 6)); + printf("%d\n", is_present(primes, real_primes, 13)); + return 0; +} diff --git a/lab4/a.out b/lab4/a.out new file mode 100755 index 0000000..b03d340 Binary files /dev/null and b/lab4/a.out differ diff --git a/lab4/i b/lab4/i new file mode 100644 index 0000000..917d342 --- /dev/null +++ b/lab4/i @@ -0,0 +1,11 @@ +10 +1 3 3 6 +2 1 1 2 2 3 3 +3 1 1 2 2 3 3 4 4 +1 7 5 10 +3 10 15 6 9 21 25 92 89 +1 1 1 2 +2 0 1 0 5 5 2 +3 0 0 0 5 5 0 5 5 +1 3 3 7 +2 5 5 6 6 7 7 diff --git a/lab4/main.c b/lab4/main.c new file mode 100644 index 0000000..e43f9dc --- /dev/null +++ b/lab4/main.c @@ -0,0 +1,235 @@ +#include +#include + +enum { point, circle, triangle, rectangle }; // Holds type data. Because numbers are too mainstream. + +typedef struct _point { + unsigned int type: 2; + int x; + int y; +} Point; + +typedef struct _circle { + unsigned int type: 2; + Point point; + int radius; +} Circle; + +typedef struct _triangle { + unsigned int type: 2; + Point points[3]; +} Triangle; + +typedef struct _rectangle { + unsigned int type: 2; // 11 + Point points[4]; +} Rectangle; + +typedef union _geo { + Point point; + Triangle triangle; + Circle circle; + Rectangle rectangle; +} Shape; + + + +// stolen from course website +typedef struct ilst *intlist_t; +intlist_t empty(void); +int isempty(intlist_t lst); +Shape head(intlist_t lst); +intlist_t tail(intlist_t lst); +intlist_t cons(Shape el, intlist_t tl); +intlist_t decons(intlist_t lst, Shape *elp); + +struct ilst { + intlist_t nxt; + Shape el; +}; + +int isempty(intlist_t lst) +{ + return lst == NULL; +} + +intlist_t empty(void) +{ + return NULL; +} + +Shape head(intlist_t lst) +{ + return lst->el; +} + +intlist_t tail(intlist_t lst) +{ + return lst->nxt; +} + +intlist_t cons(Shape el, intlist_t tl) +{ + intlist_t p = malloc(sizeof(struct ilst)); + if (!p) return NULL; + p->el = el; + p->nxt = tl; + return p; +} +// end + +// returns tail, assignes *elp with head +intlist_t decons(intlist_t lst, Shape *elp) +{ + if (elp) *elp = lst->el; + intlist_t tl = lst->nxt; + free(lst); + return tl; +} +// end stolen from course website. + +void printlist(intlist_t lst) +{ + if (isempty(lst)) putchar('\n'); + else { + if ( head(lst).point.type == 0 ) { + printf("This is a point.\n"); + printf("x: %d y: %d\n", head(lst).point.x, head(lst).point.y ); + } else if ( head(lst).point.type == circle ) { + printf("This is a Circle.\n"); + printf("x: %d y: %d\n", head(lst).circle.point.x, head(lst).circle.point.y ); + printf("radius: %d \n", head(lst).circle.radius ); + } else if ( head(lst).point.type == triangle ) { + printf("This is a Triangle.\n");//written_by_denis + printf("x: %d y: %d\n", head(lst).triangle.points[0].x, head(lst).triangle.points[0].y ); + printf("x: %d y: %d\n", head(lst).triangle.points[1].x, head(lst).triangle.points[1].y ); + printf("x: %d y: %d\n", head(lst).triangle.points[2].x, head(lst).triangle.points[2].y ); + } else if ( head(lst).point.type == rectangle ) { + printf("This is a Rectangle.\n"); + printf("x: %d y: %d\n", head(lst).rectangle.points[0].x, head(lst).rectangle.points[0].y ); + printf("x: %d y: %d\n", head(lst).rectangle.points[1].x, head(lst).rectangle.points[1].y ); + printf("x: %d y: %d\n", head(lst).rectangle.points[2].x, head(lst).rectangle.points[2].y ); + printf("x: %d y: %d\n", head(lst).rectangle.points[3].x, head(lst).rectangle.points[3].y ); + } + printlist(tail(lst)); + } +} + +void print_array(Shape * shapes, size_t size) { + for ( int i = 0; i < size; i++ ) { + if ( shapes[i].point.type == point ) { // point + printf("shapes[%d] is a point.\n", i); + printf("x: %d y: %d\n", shapes[i].point.x, shapes[i].point.y ); + } else if ( shapes[i].point.type == circle ) { + printf("shapes[%d] is a circle.\n", i); + printf("x: %d y: %d\n", shapes[i].circle.point.x, shapes[i].circle.point.y ); + printf("radius: %d\n", shapes[i].circle.radius ); + } else if ( shapes[i].point.type == triangle ) { + printf("shapes[%d] is a triangle.\n", i); + printf("x: %d y: %d\n", shapes[i].triangle.points[0].x, shapes[i].triangle.points[0].y ); + printf("x: %d y: %d\n", shapes[i].triangle.points[1].x, shapes[i].triangle.points[1].y ); + printf("x: %d y: %d\n", shapes[i].triangle.points[2].x, shapes[i].triangle.points[2].y ); + } else if ( shapes[i].point.type == rectangle ) { + printf("shapes[%d] is a triangle.\n", i); + printf("x: %d y: %d\n", shapes[i].rectangle.points[0].x, shapes[i].rectangle.points[0].y ); + printf("x: %d y: %d\n", shapes[i].rectangle.points[1].x, shapes[i].rectangle.points[1].y ); + printf("x: %d y: %d\n", shapes[i].rectangle.points[2].x, shapes[i].rectangle.points[2].y ); + printf("x: %d y: %d\n", shapes[i].rectangle.points[3].x, shapes[i].rectangle.points[3].y ); + } + } +} + +void process_input() { + int figures = -1; + intlist_t list = NULL; + printf("How many figures?\n"); + scanf("%d", &figures); + // printf("figs %d\n", figures); + printf("Adding %d figures.\n", figures); + for (int i = 0; i < figures; i++) { + int type = -1; + printf("What's the type of the figure? (1 - CIRCLE, 2 - TRIANGLE, 3 - RECTANGLE)\n"); + scanf("%d", &type); + Shape * shape; + switch (type) { + case circle: + shape = malloc(sizeof(Shape)); + shape->circle.type = circle; + printf("What's the X and Y of the circle point?\n"); + scanf("%d %d", &shape->circle.point.x, &shape->circle.point.y); + printf("What's the radius of the circle?\n"); + scanf("%d", &shape->circle.radius); + printf("Circle added, moving on!\n"); + list = cons(*shape, list); + free(shape); + break; + case triangle: + shape = malloc(sizeof(Shape)); + shape->triangle.type = triangle; + printf("What's the X and Y of the first triangle point?\n"); + scanf("%d %d", &shape->triangle.points[0].x, &shape->triangle.points[0].y); + + printf("What's the X and Y of the seccond triangle point?\n"); + scanf("%d %d", &shape->triangle.points[1].x, &shape->triangle.points[1].y); + + printf("What's the X and Y of the third triangle point?\n"); + scanf("%d %d", &shape->triangle.points[2].x, &shape->triangle.points[2].y); + + printf("Triangle added, moving on!\n"); + list = cons(*shape, list); + free(shape); + break; + case rectangle: + shape = malloc(sizeof(Shape)); + shape->rectangle.type = rectangle; + printf("What's the X and Y of the first rectangle point?\n"); + scanf("%d %d", &shape->rectangle.points[0].x, &shape->rectangle.points[0].y); + + printf("What's the X and Y of the seccond rectangle point?\n"); + scanf("%d %d", &shape->rectangle.points[1].x, &shape->rectangle.points[1].y); + + printf("What's the X and Y of the third rectangle point?\n"); + scanf("%d %d", &shape->rectangle.points[2].x, &shape->rectangle.points[2].y); + + printf("What's the X and Y of the fourth rectangle point?\n"); + scanf("%d %d", &shape->rectangle.points[3].x, &shape->rectangle.points[3].y); + + printf("Rectangle added, moving on!\n"); + list = cons(*shape, list); + free(shape); + break; + default: + fprintf(stderr, "Error, invalid type!\n"); + return; + } + } + + printf("\nPrinting...\n\n"); + printlist(list); +} + +int main() { + //METHOD ! + Shape shapes[10]; // (Cast to type) (Struct initializer) + shapes[0].point = (Point) { point, 4, 6 }; + shapes[1].point = (Point) { point, 1, 2}; + shapes[2].point = (Point) { point, 1, 2}; + shapes[3].circle = (Circle) { circle, {point, 1, 1}, 10 }; + shapes[4].circle = (Circle) { circle, {point, 5, 5}, 16 }; + shapes[5].triangle = (Triangle) { triangle, { {point, 1, 1}, {point, 2, 2}, {point, 3, 3} } }; + shapes[6].triangle = (Triangle) { triangle, { {point, 1, 1}, {point, 2, 2}, {point, 3, 9} } }; + shapes[7].circle = (Circle) { circle, {point, 52, 52}, 20 }; + shapes[8].circle = (Circle) { circle, {point, 12, 64}, 36 }; + shapes[9].triangle = (Triangle) { triangle, { {point, 10, 5}, {point, 15, 3}, {point, 21, 7} } }; + + //LIST + // intlist_t l1 = cons(shapes[0], cons(shapes[3], cons(shapes[5], cons(shapes[1], cons(shapes[2], + // cons(shapes[4], cons(shapes[6], cons(shapes[7], cons(shapes[8], cons(shapes[9], empty())))))))))); + // printlist(l1); + + //ARRAY + // print_array(shapes, 10); + + process_input(); + return 0; +} diff --git a/lab4/test.c b/lab4/test.c new file mode 100644 index 0000000..87c6675 --- /dev/null +++ b/lab4/test.c @@ -0,0 +1,22 @@ +#include + +enum cardsuit { + CLUBS = 1, + DIAMONDS = 2 , + HEARTS = 3 , + SPADES = 4 +} custom_deck [ 52 ] ; + +struct { + unsigned int age : 3; + unsigned int dayWeek: 3; + unsigned int flagValid : 1; +} Info; + +int main() { + unsigned int aux; + scanf ("%u", &aux); + if (aux == 0) Info.flagValid = 0; else Info.flagValid = 1; + if (aux > 1) fprintf(stderr , "Sir , You should be more careful with your input!\n"); + return 0; +} diff --git a/lab5/a.out b/lab5/a.out new file mode 100755 index 0000000..ddc7367 Binary files /dev/null and b/lab5/a.out differ diff --git a/lab5/tictac.c b/lab5/tictac.c new file mode 100644 index 0000000..b8c57cd --- /dev/null +++ b/lab5/tictac.c @@ -0,0 +1,283 @@ +#include +#include +#include + + +int take_corners(int); + +// explicit instantiation +int moves[9] = {0}; +int moves_made = 0; +int computer_mv = 0; + +enum { human_player = 1, computer_player = 2 }; +enum { top_left, top_middle, top_right, middle_left, middle, middle_right, + bottom_left, bottom_middle, bottom_right }; + +void display_tutorial_board() { + int move; + for (int i = 0; i < 3; i++) { + printf("|"); + for (int j = 0; j < 3; j++) { + move = j + i * 3 + 1; + printf("_%d_|", move); + } + printf("\n\n"); + } +} + +void display_board() { + char mark; + int move; + printf("\n"); + for (int i = 0; i < 3; i++) { + printf("|"); + for (int j = 0; j < 3; j++) { + + move = moves[j + i * 3]; + + if ( !move ) mark = '_'; + else if (move == human_player) mark = 'X'; + else mark = 'O'; + + printf("_%c_|", mark); + } + printf("\n\n"); + } +} + +int _check_win(int x) { + int player_wins = x; + int aux = 0; + for (int i = 0; i < 9; i += 3) { + aux |= moves[i] & moves[i+1] & moves[i+2]; // linii + } + for (int i = 0; i < 3; i++) { + aux |= moves[i] & moves[i+3] & moves[i+6]; // coloane + } + aux |= moves[top_left] & moves[middle] & moves[bottom_right]; // principal + aux |= moves[top_right] & moves[middle] & moves[bottom_left]; // secondary + player_wins &= aux; + return player_wins; +} + +int check_win() { + int player_wins = human_player; + player_wins &= _check_win(player_wins); + int computer_wins = computer_player; + computer_wins &= _check_win(computer_wins); + return player_wins | computer_wins; +} + +int block(int player) { + int move = -1; + + for (int i = 0; i < 9; i += 3) { // blocheaza liniile. + if ( ((moves[i] & moves[i + 1]) == player) && !moves[i + 2] ) { + moves[i + 2] = computer_player; + move = i + 2; + return move + 1; + } else if ( ((moves[i] & moves[i + 2]) == player) && !moves[i + 1] ) { + moves[i + 1] = computer_player; + move = i + 1; + return move + 1; + } else if ( ((moves[i + 1] & moves[i + 2]) == player) && !moves[i] ) { + moves[i] = computer_player; + move = i; + return move + 1; + } + } + + for (int i = 0; i < 3; i++) { //blocheaza coloanele + if ( ((moves[i] & moves[i + 3]) == player) && !moves[i + 6] ) { + moves[i+6] = computer_player; + move = i+6; + return move +1; + } else if ( ((moves[i] & moves[i + 6]) == player) && !moves[i + 3] ) { + moves[i+3] = computer_player; + move = i+3; + return move +1; + } else if ( ((moves[i + 3] & moves[i + 6]) == player) && !moves[i] ) { + moves[i] = computer_player; + move = i; + return move +1; + } + } + + // principal + if ( ((moves[top_left] & moves[middle]) == player) && !moves[bottom_right] ) { + moves[bottom_right] = computer_player; + return bottom_right + 1; + } else if ( ((moves[top_left] & moves[bottom_right]) == player) && !moves[middle] ) { + moves[middle] = computer_player; + return middle + 1; + } if ( ((moves[bottom_right] & moves[middle]) == player) && !moves[top_left] ) { + moves[top_left] = computer_player; + return top_left + 1; + } + + // secondary + if ( ((moves[top_right] & moves[middle]) == player) && !moves[bottom_left] ) { + moves[bottom_left] = computer_player; + return bottom_left + 1; + } else if ( ((moves[top_right] & moves[bottom_left]) == player) && !moves[middle] ) { + moves[middle] = computer_player; + return middle + 1; + } if ( ((moves[bottom_left] & moves[middle]) == player) && !moves[top_right] ) { + moves[top_right] = computer_player; + return top_right + 1; + } + return move + 1; +} + +int try_to_win(int player) { + int move = -1; + if (moves[middle] == computer_player) { + for (int i = 0; i < 9; i += 3) { // tries to make a line in order to not pun random things. + if ( (moves[i] | moves[i+1] | moves[i+2]) == player ) { + if (!moves[i]) { + moves[i] = player; + move = i; + return move + 1; + } else if (!moves[i+1]) { + moves[i + 1] = player; + move = i + 1; + return move + 1; + } else if (!moves[i+2]) { + moves[i + 2] = player; + move = i + 2; + return move + 1; + } + } + } + } else { + return take_corners(computer_player); + } + return move + 1; +} + +int computer_move() { + int move = rand() % 9; + if ( moves[move] == 0 ) { + moves[move] = 2; + } else { + return computer_move(); + } + return move + 1; +} + +int take_corners(int player) { + int move = rand() % 4; + int corners[4] = {top_left, top_right, bottom_left, bottom_right}; + + // prevent the human from playing tricks on us! + if ( ((moves[top_middle] & moves[middle_left]) == human_player) && !moves[top_left] ) { + moves[top_left] = computer_player; + return top_left + 1; + } else if ( ((moves[bottom_middle] & moves[middle_left]) == human_player) && !moves[bottom_left] ) { + moves[bottom_left] = computer_player; + return bottom_left + 1; + } else if ( ((moves[top_middle] & moves[middle_right]) == human_player) && !moves[top_right] ) { + moves[top_right] = computer_player; + return top_right + 1; + } else if ( ((moves[bottom_middle] & moves[middle_right]) == human_player) && !moves[bottom_right] ) { + moves[bottom_right] = computer_player; + return bottom_left + 1; + } + + if (!moves[corners[move]]) { // random corner + moves[corners[move]] = player; + move = corners[move] + 1; + } else { + for (int i = 0; i < 4; i++) { // take first available corner + if (!moves[corners[i]]) { + moves[corners[i]] = computer_player; + return corners[i] + 1; + } + } + return computer_move(); // dumb move + } + + return move; +} + +int computer_move_i() { + int move = 0; + + if ( !moves[middle] ) { // O marks the spot + moves[middle] = computer_player; + move = middle; + return move + 1; + } + + if ( (move = block(computer_player)) ) { + return move; + } else if ( ( move = block(human_player) ) ) { // O is taken, take corners. + return move; + } else if ( ( move = try_to_win(computer_player) ) ) { // force block. + return move; + } else { + return take_corners(computer_player); + } + return move; +} + +int game() { + int choice; + printf("Type a number between 1-9: "); + + int c = scanf("%d", &choice); + if ( c == 0 ) { + printf("\nINVALID MOVE! WATCH IT KID!\n"); + while( (c = getchar() != '\n') ); // clear STDIN + return game(); + } else if (choice < 1 || choice > 9) { + printf("\nINVALID MOVE! WATCH IT KID!\n"); + return game(); + } + + if ( moves[choice - 1] == 0) { + moves[choice - 1] = 1; + } else { + printf("\nWOHO, KID, WHATCHA DOING?!\n"); + return game(); + } + if (check_win()) { + return check_win(); + } + + moves_made++; + if ( moves_made < 9) computer_mv = computer_move_i(); // replace with computer_move for dumb play + moves_made++; + + return check_win(); +} + +void game_start() { + srand( time(NULL) ); + + printf("Hello. Imagine every box is number from 1-9.\nType your number and hit" \ + " enter.\n You are playing X.\n\n"); + display_tutorial_board(); + int winner; + int moves = 0; + + while( !( winner = game() ) && moves++ < 4 ) { + display_board(); + printf("Computer made a move at: %d\n\n", computer_mv); + }; // plays until someone wins or the board is filled. + + display_board(); + if ( winner == 1 ) { // Never going to happen. + printf("Congratulations! YOU'RE WINNER!\n"); + } else if ( winner == 2 ) { + printf("Congratulations! YOU'RE LOSSER!\n"); + } else { + printf("Congratulations! YOU'RE DRAFT!\n"); + } +} + +int main(int argc, char const *argv[]) { + game_start(); + return 0; +} diff --git a/lab6/a.out b/lab6/a.out new file mode 100755 index 0000000..0bc74d9 Binary files /dev/null and b/lab6/a.out differ diff --git a/lab6/a.out.dSYM/Contents/Info.plist b/lab6/a.out.dSYM/Contents/Info.plist new file mode 100644 index 0000000..3679a65 --- /dev/null +++ b/lab6/a.out.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.a.out + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/lab6/a.out.dSYM/Contents/Resources/DWARF/a.out b/lab6/a.out.dSYM/Contents/Resources/DWARF/a.out new file mode 100644 index 0000000..d0f53c3 Binary files /dev/null and b/lab6/a.out.dSYM/Contents/Resources/DWARF/a.out differ diff --git a/lab6/i b/lab6/i new file mode 100644 index 0000000..eae6345 --- /dev/null +++ b/lab6/i @@ -0,0 +1,10 @@ +0 +1 2 3 +0 +4 5 6 +2 +2 6 0 4 +2 +5 8 0 6 +2 +7 9 0 8 diff --git a/lab6/l6_1.c b/lab6/l6_1.c new file mode 100644 index 0000000..71408f1 --- /dev/null +++ b/lab6/l6_1.c @@ -0,0 +1,21 @@ +#include + +char code64[]="\x48\x31\xFF\x48\x31\xC0\xB0\x3C\x0F\x05"; + +/* +gcc fno stack protector -z execstack o exit exit . c ; + +*/ + +int main (void) { + + int (*func)(); /* function pointer for a function */ + /* with no arguments but with a return value */ + + func = (int (*)()) code64; /* cast from char array to function pointer */ + + (int)(*func)(); /* calls exit(0), Intel 64 bit CPU */ + + printf("Should exit(0) gracefully before getting here!\n"); +return 0; +} diff --git a/lab6/l6_2.c b/lab6/l6_2.c new file mode 100644 index 0000000..8ce2e6f --- /dev/null +++ b/lab6/l6_2.c @@ -0,0 +1,139 @@ +#include +#include +#define N 5 + +struct gshape { + int type ; /* 0/1/2 */ + int ID; + union + { + struct + { + float radius; + float x, y; + } circle; + + struct + { + float x1,y1, x2,y2, x3,y3; + } triangle; + + struct { + float x1,y1; + float x4,y4; + } rectangle ; + + } gshape ; + + /* upper left */ + /* right bottom */ + /* function pointers in struct provide contained intelligence */ + void (*read_gshape)(struct gshape *gs); + /* like an object having both data and code */ + void (*write_gshape)(struct gshape *gs); + void (*compute_area)(struct gshape *gs); +}; + +void read_circle ( struct gshape *gs) { + printf("radius? "); + scanf("%f", &(gs->gshape.circle.radius)); + printf("X center? "); + scanf("%f" , &(gs->gshape.circle.x)); + printf("Y center? "); + scanf("%f" , &(gs->gshape.circle.x)); +} + +void write_circle ( struct gshape *gs) { + printf("Circle Radius: %f X: %f Y: %f\n", gs->gshape.circle.radius, + gs->gshape.circle.x, + gs->gshape.circle.y); +} + +void read_triangle ( struct gshape *gs) { + printf("What is the triangle coordonates? (x1,y1) (x2,y2), (x3,y3)\n"); + scanf("%f %f %f %f %f %f", &gs->gshape.rectangle.x1, + &gs->gshape.triangle.y1, + &gs->gshape.triangle.x2, + &gs->gshape.triangle.y2, + &gs->gshape.triangle.x3, + &gs->gshape.triangle.y3); +} + + +void write_triangle ( struct gshape *gs) { + printf("Triangle (%f,%f) (%f,%f), (%f,%f)\n", gs->gshape.triangle.x1, + gs->gshape.triangle.y1, + gs->gshape.triangle.x2, + gs->gshape.triangle.y2, + gs->gshape.triangle.x3, + gs->gshape.triangle.y3); +} + +void read_rectangle(struct gshape *gs) { + printf("What's the A B C D of the Rectangle?\n" ); + scanf("%f %f %f %f", &gs->gshape.rectangle.x1, + &gs->gshape.rectangle.y1, + &gs->gshape.rectangle.x4, + &gs->gshape.rectangle.y4); +} + +void write_rectangle( struct gshape *gs) { + printf("Heres's the A B C D of the Rectangle\n" ); + printf("%f %f %f %f\n", gs->gshape.rectangle.x1, + gs->gshape.rectangle.y1, + gs->gshape.rectangle.x4, + gs->gshape.rectangle.y4); +} + +void area_rectangle(struct gshape *gs) { + double length = gs->gshape.rectangle.x4 - gs->gshape.rectangle.x1; + double width = gs->gshape.rectangle.y4 - gs->gshape.rectangle.x4; + printf("AREA OF RECTANGLE #%d IS: %g\n", gs->ID, fabs(length*width) ); +} + +int main() { + int i, type; + struct gshape gs[N]; + for (i = 0; i < N; i++) { + do { + printf("ShapeID %d: ", i); + printf("What type of shape is it? (0=circle , 1=triangle , 2=rectangle)\n"); + scanf("%d", &type); + gs[i].type = type; + gs[i].ID = i; + switch (gs[i].type) { + case 0: + gs[i].read_gshape = &read_circle; + gs[i].write_gshape = &write_circle; + gs[i].read_gshape(&gs[i]); + gs[i].write_gshape(&gs[i]); + break; + case 1: + gs[i].read_gshape = &read_triangle; + gs[i].write_gshape = &write_triangle; + gs[i].read_gshape(&gs[i]); + gs[i].write_gshape(&gs[i]); + break; + case 2: + gs[i].read_gshape = &read_rectangle; + gs[i].write_gshape = &write_rectangle; + gs[i].compute_area = &area_rectangle; + + // calls + gs[i].read_gshape(&gs[i]); + gs[i].write_gshape(&gs[i]); + break; + default: + fprintf(stderr, "Err!\n"); + } + } while ((gs[i].type != 0) && (gs[i].type != 1) && (gs[i].type != 2)); + } + + // COMPUTE AREA + printf("\n\n"); + for (int i = 0; i < N; i++) { + if (gs[i].type == 2) { + gs[i].compute_area(&gs[i]); + } + } +} diff --git a/lab6/l6_3.c b/lab6/l6_3.c new file mode 100644 index 0000000..db031ad --- /dev/null +++ b/lab6/l6_3.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +/* float is automatically promoted to double via ... +because of the stack memory requirements */ +double arithmetic_mean(unsigned int n, ...) { + va_list valist; + float sum = 0.0; + unsigned int i; + /* initialize valist for n arguments */ + va_start(valist , n); + + /* parse n arguments of type float from valist */ + for (i = 0; i < n; i++) { + sum += va_arg(valist , double); + } + + /* clean valist */ + va_end( valist ); + return sum/n; +} + +void max_and_min(int * max, int * min, int n, ...) { + va_list valist; + /* initialize valist for n arguments */ + va_start(valist , n); + + *max = va_arg(valist, int); + *min = va_arg(valist, int); + if ( *max < *min) { + int aux = *max; + *max = *min; + *min = aux; + } + + int el; + for (int i = 0; i < n-2; i++) { + el = va_arg(valist , int); + if ( el >= *max ) { + *max = el; + } + else if ( el < *min ) { + *min = el; + } + } + + /* clean valist */ + va_end( valist ); +} + +int main() { + int max; + int min; + max_and_min(&max, &min, 10, 1, -1, 1, 3, 4, -6, 6, 8, 9, 10); + printf("Max: %d Min: %d\n", max, min); + return 0; +} diff --git a/lab6/l6_4.c b/lab6/l6_4.c new file mode 100644 index 0000000..532c1a5 --- /dev/null +++ b/lab6/l6_4.c @@ -0,0 +1,89 @@ +#include +#include + +double (*primary[7])(double); +char *secondary[] = { "sin(x)", "cos(x)", "ceil(x)", "floor(x)", "fabs(x)", "log(x)", "sqrt(x)" }; + +void process_choice(); +void map_function_pointers(double (**arr)(double), int pos, int n) { + switch (n) { + case 0: + arr[pos] = sin; + break; + case 1: + arr[pos] = cos; + break; + case 2: + arr[pos] = ceil; + break; + case 3: + arr[pos] = floor; + break; + case 4: + arr[pos] = fabs; + break; + case 5: + arr[pos] = log; + break; + case 6: + arr[pos] = sqrt; + break; + default: + fprintf(stderr, "Error\n"); + } +} + +void clean_stdin() { + int c; while ( (c = getchar()) != '\n' ); +} + +void display_menu() { + for (int i = 0; i < 7; i++) { + printf("%d. %s\n", i, secondary[i]); + } +} + +void init() { + for (int i = 0; i < 7; i++) { + map_function_pointers(primary, i, i); + } +} + +int is_valid(int flag) { + if (!flag) { + fprintf(stderr, "Invalid choice!\n"); + clean_stdin(); + return 0; + } + return 1; +} + +void process_choice() { + display_menu(); + int choice = -1; + double value = 0; + + printf("Choice: "); + int flag = scanf("%d", &choice); + if ( !is_valid(flag) ) { return process_choice(); } + if (choice < 0 || choice > 6) { + fprintf(stderr, "Out of range choice!\n"); + return process_choice(); + } + + printf("Enter a value: "); + int value_flag = scanf("%lf", &value); + if ( !is_valid(value_flag) ) { + fprintf(stderr, "Invalid value!\n"); + return process_choice(); + } + + printf("RESULT: %f\n", primary[choice](value)); + +} + +int main() { + init(); + process_choice(); + return 0; +} diff --git a/lab7/2.c b/lab7/2.c new file mode 100644 index 0000000..f105809 --- /dev/null +++ b/lab7/2.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +void count_letter_frequency_from_file(char * filename) { + FILE * file; + file = fopen(filename, "r"); // filename, mode + + // open + if ( !file ) { + fprintf(stderr, "Error opening file.\n"); + exit(errno); // exit + } + + int frequencies[128] = { 0 }; // Contains character frequencies from ascii table, is initialized to 0; + char * line = malloc( 200 ); // becauase 1 char = 1 byte, 200 chars = 200 bytes + while ( fgets(line, 200, file) ) { // max 200 chars pe line, gets the line + for ( int i = 0; line[i]; i++ ) { // process the line char by char + frequencies[ (int) line[i] ]++; // make the letter and decimal and increments it's possition in the array. + } + } + + printf("Characters - Frequencies\n"); + for (int i = 0; i < 128; i++) { + if ( frequencies[i] && isprint( (char) i ) ) { // different from zero and printable + printf( "\t %c - %d\n", i, frequencies[i] ); + } + } + + // close + if ( fclose(file) ) { + fprintf(stderr, "Error closing file\n"); + exit(errno); + } + + free(line); +} + +int main() { + count_letter_frequency_from_file("test"); + return 0; +} diff --git a/lab7/3.c b/lab7/3.c new file mode 100644 index 0000000..f28ab58 --- /dev/null +++ b/lab7/3.c @@ -0,0 +1,51 @@ +#include +#include +#include + + +// won't work on windaws. +void unix_to_dos(char * filename) { + // "Use the stdin and stdout file streams." NO. + FILE * file = fopen(filename, "r"); + FILE * out; + // open + if ( !file ) { + fprintf(stderr, "Error opening file.\n"); + exit(errno); // exit + } + + system("touch converted.txt"); // create new file. + if ( !(out = fopen("converted.txt", "w")) ) { + fprintf(stderr, "Error opening output file. Are you using windows?\n"); + exit(errno); // exit + } + + int c; + while ( (c = fgetc(file)) != EOF ) { + if ( c == '\n') { + fputc('\r', out); // we're placing the character in the out file. + fputc(c, out); // c is newline. + } else { + fputc(c, out); // c is whatever + } + } + + + // close + if ( fclose(file) || fclose(out) ) { // fclose returns zero on successful close + fprintf(stderr, "Error closing file\n"); + exit(errno); + } +} + +int main(int argc, char *argv[]) { + if ( argc != 2) { + fprintf(stderr, "Invalid number of arguments.\n"); + fprintf(stderr, "Correct ussage: %s filename\n", argv[0]); + return 1; + } + + unix_to_dos(argv[1]); + + return 0; +} diff --git a/lab7/4.c b/lab7/4.c new file mode 100644 index 0000000..f2de18f --- /dev/null +++ b/lab7/4.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +// won't work on windaws. +void unix_to_dos(char * filename) { + FILE * file = fopen(filename, "r"); + FILE * out; + // open + if ( !file ) { + fprintf(stderr, "Error opening file.\n"); + exit(errno); // exit + } + + // It would have been easier if we worked on the current file, + // without creating a separated file for the converted file. + char * out_filename = malloc( 5 + strlen(filename) ); // dos_ (4) + filename (strlen) + NULL (1) + memcpy( out_filename, "dos_", 4 ); + memcpy( out_filename + 4, filename, strlen(filename) + 1 ); // + 1 to copy the null + // we want to perform the following command: + // touch dos_filename.ext + // 5 + 1 + strlen(out_filename) + 1 + char * command = malloc( 7 + strlen(out_filename) ); + memcpy(command, "touch ", 6); + memcpy(command + 6, out_filename, strlen(out_filename) + 1); // + 1 to copy the terminating NULL + + system(command); // create new file. + if ( !(out = fopen(out_filename, "w")) ) { + fprintf(stderr, "Error opening output file. Are you using windows?\n"); + exit(errno); // exit + } + + int c; + while ( (c = fgetc(file)) != EOF ) { + if ( c == '\n') { + fputc('\r', out); // we're placing the character in the out file. + fputc(c, out); // c is newline. + } else { + fputc(c, out); // c is whatever + } + } + + // close + if ( fclose(file) || fclose(out) ) { // fclose returns zero on successful close + fprintf(stderr, "Error closing file\n"); + exit(errno); + } + free(out_filename); + free(command); +} + +int main(int argc, char *argv[]) { + if ( argc < 2) { + fprintf(stderr, "Invalid number of arguments.\n"); + fprintf(stderr, "Correct ussage: %s filename\n", argv[0]); + return 1; + } + + // *.c will expand to all the files in the current dir. eg: 1.c 2.c 3.c et.c + for (int i = 1; i < argc; i++) { + unix_to_dos( argv[i] ); + } + + return 0; +} diff --git a/lab7/5.c b/lab7/5.c new file mode 100644 index 0000000..7327ae3 --- /dev/null +++ b/lab7/5.c @@ -0,0 +1,115 @@ +#include +#include +#include +#include + +#define LINE_CHARS 100 + +// Parser +int zfind(char *str, int c) { + for (int i = 0; str[i]; i++) { + if (str[i] == c) { return 1; } + } + return 0; +} + +// easy solution, no memory leak :) +char * parse_html(char *string){ + char * ptr = malloc( LINE_CHARS ); + int index = 0; + for (int i = 0; string[i]; i++) { + if (string[i] == '<') { // found opening bracket + if ( zfind(string + i, '>')) { // found closing bracket + while(string[i] != '>') { i++; }; // delete za tag + } else { + ptr[index++] = string[i]; // didn't find closing bracket, skip + } + } else { + ptr[index++] = string[i]; // normal character + } + } + ptr[index] = '\0'; + + return ptr; +} + +// Time shift +void shift_time(int *h, int *m, int *s, int *scr_h, int *scr_m, int *scr_s, int shift) { + long mhs = (*h * 3600) + (*m * 60) + *s + shift; + long scr_mhs = (*scr_h * 3600) + (*scr_m * 60) + *scr_s + shift; + *h = mhs / 3600; + *m = (mhs / 60) % 60; + *s = mhs % 60; + *scr_h = scr_mhs / 3600; + *scr_m = (scr_mhs / 60) % 60; + *scr_s = scr_mhs % 60; +} + +// Reader +void process_subtitles(char * filename, int time) { + FILE * file; + FILE * out; + if ( !(file = fopen(filename , "r")) ) { + fprintf(stderr, "Error, can't open file: %s\n", filename); + exit(errno); + } + system("touch working.srt"); + if ( !(out = fopen("working.srt" , "w")) ) { + fprintf(stderr, "Error, can't open file: working.srt\n"); + exit(errno); + } + + char * line = malloc ( LINE_CHARS ); + char * temp; + int line_no; + int h, m, s, ms, scr_h, scr_m, scr_s, scr_ms; + + while(1) {// infinity. Executes the folowing wile for eternity. + // read numbers + while ( fscanf(file, "%d\r\n%d:%d:%d,%d --> %d:%d:%d,%d\r\n", + &line_no, &h, &m, &s, &ms, &scr_h, &scr_m, &scr_s, &scr_ms) ) { + if (feof(file)) { break; } + + if(time) { + shift_time(&h, &m, &s, &scr_h, &scr_m, &scr_s, time); + } + + // print formatted time. + fprintf(out, "%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n", + line_no, h, m, s, ms, scr_h, scr_m, scr_s, scr_ms); + + while ( fgets(line, LINE_CHARS - 1, file) ) { // read sub diaglog + temp = parse_html(line); + fprintf(out, "%s", temp); + free(temp); // prevent memory leak by freeing the pointer. + if (!strcmp(line, "\r\n")) { break; } + } + } + + if (feof(file)) { break; } + } + + + if ( fclose(file) || fclose(out) ) { + printf("Error, can't close file\n"); + exit(errno); + } + + free(line); +} + +int main(int argc, char *argv[]) { + if ( argc < 2) { + fprintf(stderr, "Invalid number of arguments.\n"); + fprintf(stderr, "Correct ussage: %s filename [secconds to shift]\n", argv[0]); + return 1; + } + + int time_to_shift = 0; + if ( argc > 2) { + time_to_shift = atoi(argv[2]); + } + + process_subtitles(argv[1], time_to_shift); + return 0; +} diff --git a/lab7/a.out b/lab7/a.out new file mode 100755 index 0000000..02e158e Binary files /dev/null and b/lab7/a.out differ diff --git a/lab7/a.out.dSYM/Contents/Info.plist b/lab7/a.out.dSYM/Contents/Info.plist new file mode 100644 index 0000000..3679a65 --- /dev/null +++ b/lab7/a.out.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.a.out + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/lab7/a.out.dSYM/Contents/Resources/DWARF/a.out b/lab7/a.out.dSYM/Contents/Resources/DWARF/a.out new file mode 100644 index 0000000..fabbb14 Binary files /dev/null and b/lab7/a.out.dSYM/Contents/Resources/DWARF/a.out differ diff --git a/lab7/converted.txt b/lab7/converted.txt new file mode 100644 index 0000000..c3d1c14 --- /dev/null +++ b/lab7/converted.txt @@ -0,0 +1,284 @@ +/* tic tac toe */ +#include +#include +#include + + +int take_corners(int); + +// explicit instantiation +int moves[9] = {0}; +int moves_made = 0; +int computer_mv = 0; + +enum { human_player = 1, computer_player = 2 }; +enum { top_left, top_middle, top_right, middle_left, middle, middle_right, + bottom_left, bottom_middle, bottom_right }; + +void display_tutorial_board() { + int move; + for (int i = 0; i < 3; i++) { + printf("|"); + for (int j = 0; j < 3; j++) { + move = j + i * 3 + 1; + printf("_%d_|", move); + } + printf("\n\n"); + } +} + +void display_board() { + char mark; + int move; + printf("\n"); + for (int i = 0; i < 3; i++) { + printf("|"); + for (int j = 0; j < 3; j++) { + + move = moves[j + i * 3]; + + if ( !move ) mark = '_'; + else if (move == human_player) mark = 'X'; + else mark = 'O'; + + printf("_%c_|", mark); + } + printf("\n\n"); + } +} + +int _check_win(int x) { + int player_wins = x; + int aux = 0; + for (int i = 0; i < 9; i += 3) { + aux |= moves[i] & moves[i+1] & moves[i+2]; // linii + } + for (int i = 0; i < 3; i++) { + aux |= moves[i] & moves[i+3] & moves[i+6]; // coloane + } + aux |= moves[top_left] & moves[middle] & moves[bottom_right]; // principal + aux |= moves[top_right] & moves[middle] & moves[bottom_left]; // secondary + player_wins &= aux; + return player_wins; +} + +int check_win() { + int player_wins = human_player; + player_wins &= _check_win(player_wins); + int computer_wins = computer_player; + computer_wins &= _check_win(computer_wins); + return player_wins | computer_wins; +} + +int block(int player) { + int move = -1; + + for (int i = 0; i < 9; i += 3) { // blocheaza liniile. + if ( ((moves[i] & moves[i + 1]) == player) && !moves[i + 2] ) { + moves[i + 2] = computer_player; + move = i + 2; + return move + 1; + } else if ( ((moves[i] & moves[i + 2]) == player) && !moves[i + 1] ) { + moves[i + 1] = computer_player; + move = i + 1; + return move + 1; + } else if ( ((moves[i + 1] & moves[i + 2]) == player) && !moves[i] ) { + moves[i] = computer_player; + move = i; + return move + 1; + } + } + + for (int i = 0; i < 3; i++) { //blocheaza coloanele + if ( ((moves[i] & moves[i + 3]) == player) && !moves[i + 6] ) { + moves[i+6] = computer_player; + move = i+6; + return move +1; + } else if ( ((moves[i] & moves[i + 6]) == player) && !moves[i + 3] ) { + moves[i+3] = computer_player; + move = i+3; + return move +1; + } else if ( ((moves[i + 3] & moves[i + 6]) == player) && !moves[i] ) { + moves[i] = computer_player; + move = i; + return move +1; + } + } + + // principal + if ( ((moves[top_left] & moves[middle]) == player) && !moves[bottom_right] ) { + moves[bottom_right] = computer_player; + return bottom_right + 1; + } else if ( ((moves[top_left] & moves[bottom_right]) == player) && !moves[middle] ) { + moves[middle] = computer_player; + return middle + 1; + } if ( ((moves[bottom_right] & moves[middle]) == player) && !moves[top_left] ) { + moves[top_left] = computer_player; + return top_left + 1; + } + + // secondary + if ( ((moves[top_right] & moves[middle]) == player) && !moves[bottom_left] ) { + moves[bottom_left] = computer_player; + return bottom_left + 1; + } else if ( ((moves[top_right] & moves[bottom_left]) == player) && !moves[middle] ) { + moves[middle] = computer_player; + return middle + 1; + } if ( ((moves[bottom_left] & moves[middle]) == player) && !moves[top_right] ) { + moves[top_right] = computer_player; + return top_right + 1; + } + return move + 1; +} + +int try_to_win(int player) { + int move = -1; + if (moves[middle] == computer_player) { + for (int i = 0; i < 9; i += 3) { // tries to make a line in order to not pun random things. + if ( (moves[i] | moves[i+1] | moves[i+2]) == player ) { + if (!moves[i]) { + moves[i] = player; + move = i; + return move + 1; + } else if (!moves[i+1]) { + moves[i + 1] = player; + move = i + 1; + return move + 1; + } else if (!moves[i+2]) { + moves[i + 2] = player; + move = i + 2; + return move + 1; + } + } + } + } else { + return take_corners(computer_player); + } + return move + 1; +} + +int computer_move() { + int move = rand() % 9; + if ( moves[move] == 0 ) { + moves[move] = 2; + } else { + return computer_move(); + } + return move + 1; +} + +int take_corners(int player) { + int move = rand() % 4; + int corners[4] = {top_left, top_right, bottom_left, bottom_right}; + + // prevent the human from playing tricks on us! + if ( ((moves[top_middle] & moves[middle_left]) == human_player) && !moves[top_left] ) { + moves[top_left] = computer_player; + return top_left + 1; + } else if ( ((moves[bottom_middle] & moves[middle_left]) == human_player) && !moves[bottom_left] ) { + moves[bottom_left] = computer_player; + return bottom_left + 1; + } else if ( ((moves[top_middle] & moves[middle_right]) == human_player) && !moves[top_right] ) { + moves[top_right] = computer_player; + return top_right + 1; + } else if ( ((moves[bottom_middle] & moves[middle_right]) == human_player) && !moves[bottom_right] ) { + moves[bottom_right] = computer_player; + return bottom_left + 1; + } + + if (!moves[corners[move]]) { // random corner + moves[corners[move]] = player; + move = corners[move] + 1; + } else { + for (int i = 0; i < 4; i++) { // take first available corner + if (!moves[corners[i]]) { + moves[corners[i]] = computer_player; + return corners[i] + 1; + } + } + return computer_move(); // dumb move + } + + return move; +} + +int computer_move_i() { + int move = 0; + + if ( !moves[middle] ) { // O marks the spot + moves[middle] = computer_player; + move = middle; + return move + 1; + } + + if ( (move = block(computer_player)) ) { + return move; + } else if ( ( move = block(human_player) ) ) { // O is taken, take corners. + return move; + } else if ( ( move = try_to_win(computer_player) ) ) { // force block. + return move; + } else { + return take_corners(computer_player); + } + return move; +} + +int game() { + int choice; + printf("Type a number between 1-9: "); + + int c = scanf("%d", &choice); + if ( c == 0 ) { + printf("\nINVALID MOVE! WATCH IT KID!\n"); + while( (c = getchar() != '\n') ); // clear STDIN + return game(); + } else if (choice < 1 || choice > 9) { + printf("\nINVALID MOVE! WATCH IT KID!\n"); + return game(); + } + + if ( moves[choice - 1] == 0) { + moves[choice - 1] = 1; + } else { + printf("\nWOHO, KID, WHATCHA DOING?!\n"); + return game(); + } + if (check_win()) { + return check_win(); + } + + moves_made++; + if ( moves_made < 9) computer_mv = computer_move_i(); // replace with computer_move for dumb play + moves_made++; + + return check_win(); +} + +void game_start() { + srand( time(NULL) ); + + printf("Hello. Imagine every box is number from 1-9.\nType your number and hit" \ + " enter.\n You are playing X.\n\n"); + display_tutorial_board(); + int winner; + int moves = 0; + + while( !( winner = game() ) && moves++ < 4 ) { + display_board(); + printf("Computer made a move at: %d\n\n", computer_mv); + }; // plays until someone wins or the board is filled. + + display_board(); + if ( winner == 1 ) { // Never going to happen. + printf("Congratulations! YOU'RE WINNER!\n"); + } else if ( winner == 2 ) { + printf("Congratulations! YOU'RE LOSSER!\n"); + } else { + printf("Congratulations! YOU'RE DRAFT!\n"); + } +} + +int main(int argc, char const *argv[]) { + game_start(); + return 0; +} diff --git a/lab7/dos_2.c b/lab7/dos_2.c new file mode 100644 index 0000000..ec536f9 --- /dev/null +++ b/lab7/dos_2.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +void count_letter_frequency_from_file(char * filename) { + FILE * file; + file = fopen(filename, "r"); // filename, mode + + // open + if ( !file ) { + fprintf(stderr, "Error opening file.\n"); + exit(errno); // exit + } + + int frequencies[128] = { 0 }; // Contains character frequencies from ascii table, is initialized to 0; + char * line = malloc( 200 ); // becauase 1 char = 1 byte, 200 chars = 200 bytes + while ( fgets(line, 200, file) ) { // max 200 chars pe line, gets the line + for ( int i = 0; line[i]; i++ ) { // process the line char by char + frequencies[ (int) line[i] ]++; // make the letter and decimal and increments it's possition in the array. + } + } + + printf("Characters - Frequencies\n"); + for (int i = 0; i < 128; i++) { + if ( frequencies[i] && isprint( (char) i ) ) { // different from zero and printable + printf( "\t %c - %d\n", i, frequencies[i] ); + } + } + + // close + if ( fclose(file) ) { + fprintf(stderr, "Error closing file\n"); + exit(errno); + } + + free(line); +} + +int main() { + count_letter_frequency_from_file("test"); + return 0; +} diff --git a/lab7/dos_3.c b/lab7/dos_3.c new file mode 100644 index 0000000..067f236 --- /dev/null +++ b/lab7/dos_3.c @@ -0,0 +1,51 @@ +#include +#include +#include + + +// won't work on windaws. +void unix_to_dos(char * filename) { + // "Use the stdin and stdout file streams." NO. + FILE * file = fopen(filename, "r"); + FILE * out; + // open + if ( !file ) { + fprintf(stderr, "Error opening file.\n"); + exit(errno); // exit + } + + system("touch converted.txt"); // create new file. + if ( !(out = fopen("converted.txt", "w")) ) { + fprintf(stderr, "Error opening output file. Are you using windows?\n"); + exit(errno); // exit + } + + int c; + while ( (c = fgetc(file)) != EOF ) { + if ( c == '\n') { + fputc('\r', out); // we're placing the character in the out file. + fputc(c, out); // c is newline. + } else { + fputc(c, out); // c is whatever + } + } + + + // close + if ( fclose(file) || fclose(out) ) { // fclose returns zero on successful close + fprintf(stderr, "Error closing file\n"); + exit(errno); + } +} + +int main(int argc, char *argv[]) { + if ( argc != 2) { + fprintf(stderr, "Invalid number of arguments.\n"); + fprintf(stderr, "Correct ussage: %s filename\n", argv[0]); + return 1; + } + + unix_to_dos(argv[1]); + + return 0; +} diff --git a/lab7/dos_4.c b/lab7/dos_4.c new file mode 100644 index 0000000..a9027f2 --- /dev/null +++ b/lab7/dos_4.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +// won't work on windaws. +void unix_to_dos(char * filename) { + FILE * file = fopen(filename, "r"); + FILE * out; + // open + if ( !file ) { + fprintf(stderr, "Error opening file.\n"); + exit(errno); // exit + } + + // It would have been easier if we worked on the current file, + // without creating a separated file for the converted file. + char * out_filename = malloc( 5 + strlen(filename) ); // dos_ (4) + filename (strlen) + NULL (1) + memcpy( out_filename, "dos_", 4 ); + memcpy( out_filename + 4, filename, strlen(filename) + 1 ); // + 1 to copy the null + // we want to perform the following command: + // touch dos_filename.ext + // 5 + 1 + strlen(out_filename) + 1 + char * command = malloc( 7 + strlen(out_filename) ); + memcpy(command, "touch ", 6); + memcpy(command + 6, out_filename, strlen(out_filename) + 1); // + 1 to copy the terminating NULL + + system(command); // create new file. + if ( !(out = fopen(out_filename, "w")) ) { + fprintf(stderr, "Error opening output file. Are you using windows?\n"); + exit(errno); // exit + } + + int c; + while ( (c = fgetc(file)) != EOF ) { + if ( c == '\n') { + fputc('\r', out); // we're placing the character in the out file. + fputc(c, out); // c is newline. + } else { + fputc(c, out); // c is whatever + } + } + + // close + if ( fclose(file) || fclose(out) ) { // fclose returns zero on successful close + fprintf(stderr, "Error closing file\n"); + exit(errno); + } + free(out_filename); + free(command); +} + +int main(int argc, char *argv[]) { + if ( argc < 2) { + fprintf(stderr, "Invalid number of arguments.\n"); + fprintf(stderr, "Correct ussage: %s filename\n", argv[0]); + return 1; + } + + // *.c will expand to all the files in the current dir. eg: 1.c 2.c 3.c et.c + for (int i = 1; i < argc; i++) { + unix_to_dos( argv[i] ); + } + + return 0; +} diff --git a/lab7/dos_5.c b/lab7/dos_5.c new file mode 100644 index 0000000..d9318be --- /dev/null +++ b/lab7/dos_5.c @@ -0,0 +1,115 @@ +#include +#include +#include +#include + +#define LINE_CHARS 100 + +// Parser +int zfind(char *str, int c) { + for (int i = 0; str[i]; i++) { + if (str[i] == c) { return 1; } + } + return 0; +} + +// easy solution, no memory leak :) +char * parse_html(char *string){ + char * ptr = malloc( LINE_CHARS ); + int index = 0; + for (int i = 0; string[i]; i++) { + if (string[i] == '<') { // found opening bracket + if ( zfind(string + i, '>')) { // found closing bracket + while(string[i] != '>') { i++; }; // delete za tag + } else { + ptr[index++] = string[i]; // didn't find closing bracket, skip + } + } else { + ptr[index++] = string[i]; // normal character + } + } + ptr[index] = '\0'; + + return ptr; +} + +// Time shift +void shift_time(int *h, int *m, int *s, int *scr_h, int *scr_m, int *scr_s, int shift) { + long mhs = (*h * 3600) + (*m * 60) + *s + shift; + long scr_mhs = (*scr_h * 3600) + (*scr_m * 60) + *scr_s + shift; + *h = mhs / 3600; + *m = (mhs / 60) % 60; + *s = mhs % 60; + *scr_h = scr_mhs / 3600; + *scr_m = (scr_mhs / 60) % 60; + *scr_s = scr_mhs % 60; +} + +// Reader +void process_subtitles(char * filename, int time) { + FILE * file; + FILE * out; + if ( !(file = fopen(filename , "r")) ) { + fprintf(stderr, "Error, can't open file: %s\n", filename); + exit(errno); + } + system("touch working.srt"); + if ( !(out = fopen("working.srt" , "w")) ) { + fprintf(stderr, "Error, can't open file: working.srt\n"); + exit(errno); + } + + char * line = malloc ( LINE_CHARS ); + char * temp; + int line_no; + int h, m, s, ms, scr_h, scr_m, scr_s, scr_ms; + + while(1) {// infinity. Executes the folowing wile for eternity. + // read numbers + while ( fscanf(file, "%d\r\n%d:%d:%d,%d --> %d:%d:%d,%d\r\n", + &line_no, &h, &m, &s, &ms, &scr_h, &scr_m, &scr_s, &scr_ms) ) { + if (feof(file)) { break; } + + if(time) { + shift_time(&h, &m, &s, &scr_h, &scr_m, &scr_s, time); + } + + // print formatted time. + fprintf(out, "%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n", + line_no, h, m, s, ms, scr_h, scr_m, scr_s, scr_ms); + + while ( fgets(line, LINE_CHARS - 1, file) ) { // read sub diaglog + temp = parse_html(line); + fprintf(out, "%s", temp); + free(temp); // prevent memory leak by freeing the pointer. + if (!strcmp(line, "\r\n")) { break; } + } + } + + if (feof(file)) { break; } + } + + + if ( fclose(file) || fclose(out) ) { + printf("Error, can't close file\n"); + exit(errno); + } + + free(line); +} + +int main(int argc, char *argv[]) { + if ( argc < 2) { + fprintf(stderr, "Invalid number of arguments.\n"); + fprintf(stderr, "Correct ussage: %s filename [secconds to shift]\n", argv[0]); + return 1; + } + + int time_to_shift = 0; + if ( argc > 2) { + time_to_shift = atoi(argv[2]); + } + + process_subtitles(argv[1], time_to_shift); + return 0; +} diff --git a/lab7/g.srt b/lab7/g.srt new file mode 100755 index 0000000..6da1da4 --- /dev/null +++ b/lab7/g.srt @@ -0,0 +1,2421 @@ +1 +00:00:00,805 --> 00:00:03,467 +Mii de mulțumiri George RR Martin, HBO, +Filelist, Laura Bocancios, honeybunny și... + +2 +00:00:03,503 --> 00:00:05,966 +Vouă, fanilor români de pretutindeni, +care ați apreciat traducerile noastre. + +3 +00:00:06,071 --> 00:00:11,058 +Iată cum se încheie sezonul V din +URZEALA TRONURILOR: + +4 +00:00:17,207 --> 00:00:21,596 +KINGSLANDING - DEBARCADERUL REGELUI +Capitala Celor Șapte Regate + +5 +00:00:21,616 --> 00:00:24,321 +Reședința regelui Tommen +pe linia Baratheon-Lannister + +6 +00:00:24,361 --> 00:00:28,200 +De fapt, fiul mai mic rezultat +din incestul Cersei-Jamie Lannister + +7 +00:00:31,953 --> 00:00:35,208 +WINTERFELL +Fosta reședință a Casei Stark + +8 +00:00:36,630 --> 00:00:40,208 +COPACUL INIMII +Simbol al credinței în Zeii Nordului + +9 +00:00:44,520 --> 00:00:46,650 +KINGSROAD +DRUMUL REGELUI + +10 +00:00:47,839 --> 00:00:52,061 +ZIDUL - îi desparte +pe oamenii din Cele Șapte Regate + +11 +00:00:52,460 --> 00:00:54,297 +de cei aflați Dincolo: + +12 +00:00:54,448 --> 00:00:59,339 +Sălbaticii, Oamenii liberi, și... +Ceilalți, Umblătorii Albi + +13 +00:01:03,351 --> 00:01:07,488 +BRAAVOS, unul dintre Orașele Libere, +aici se află Arya Stark + +14 +00:01:11,038 --> 00:01:13,527 +TITANUL DIN BRAAVOS + +15 +00:01:18,424 --> 00:01:20,623 +MEEREEN +Oraș din Golful Sclavilor + +16 +00:01:20,861 --> 00:01:22,111 +MAREA PIRAMIDĂ + +17 +00:01:22,421 --> 00:01:26,411 +Reședința Reginei Daenerys Targaryen +și a celor trei dragoni ai săi + +18 +00:01:26,414 --> 00:01:28,485 +Drogon, Viserion și Rhaegal + +19 +00:01:32,635 --> 00:01:35,225 +DORNE - reședința Casei Martell +Aici se află Myrcella, fiica lui Cersei + +20 +00:01:35,228 --> 00:01:38,335 +Pe ea vor să o aducă acasă +Jamie Lannister și Bronn + +21 +00:01:42,697 --> 00:01:47,721 +5x10 "Mila Mamei" +by dr.MI, Azael & Kprice + +22 +00:01:47,729 --> 00:01:51,539 +Subtitrări-noi Team +www.subtitrari-noi.ro + +23 +00:01:53,062 --> 00:01:59,090 +Sincronizare: Agentuoo7 +Subtitrări-Noi Team - www.subtitrari-noi.ro + +24 +00:02:06,738 --> 00:02:09,271 +Se întețește vântul! + +25 +00:02:11,441 --> 00:02:16,862 +Stăpânul Luminii și-a ținut făgăduiala, +regele meu. Focul său a topit zăpezile. + +26 +00:02:16,897 --> 00:02:20,065 +- Drumul înainte e liber. +- Pornim spre Winterfell. + +27 +00:02:20,084 --> 00:02:21,534 +Și ai să-l cucerești. + +28 +00:02:23,087 --> 00:02:26,539 +Stăpânul Luminii mi-a arătat +flamurile lui Bolton în flăcări. + +29 +00:02:26,574 --> 00:02:29,209 +Ai să primești ceea ce e al tău +de drept. + +30 +00:02:50,448 --> 00:02:53,531 +- Înălțimea Ta! +- Pregătiți-vă de marș! + +31 +00:02:53,568 --> 00:02:55,283 +Înălțimea Ta... + +32 +00:02:58,655 --> 00:02:59,938 +Spune! + +33 +00:02:59,956 --> 00:03:03,626 +Oștenii... +mulți au dezertat până în zori. + +34 +00:03:06,214 --> 00:03:09,915 +- Câți? +- Aproape jumătate. + +35 +00:03:09,950 --> 00:03:12,801 +Toți mercenarii și au luat și toți caii. + +36 +00:03:23,598 --> 00:03:25,730 +Înălțimea Ta... + +37 +00:03:27,468 --> 00:03:31,102 +Vorbește! +Nu poate fi mai rău ca rebeliunea. + +38 +00:04:01,601 --> 00:04:03,552 +Dați-o jos! + +39 +00:04:16,684 --> 00:04:18,533 +Înălțimea Ta! + +40 +00:04:18,568 --> 00:04:21,537 +Lady Melisandre a fost văzută +părăsind tabăra. + +41 +00:04:33,800 --> 00:04:35,918 +Adună oștenii în formație de marș. + +42 +00:04:37,872 --> 00:04:39,888 +Pornim spre winterfell. + +43 +00:04:44,394 --> 00:04:49,848 +Și-a ridicat mâinile +și toți au prins viață. + +44 +00:04:52,570 --> 00:04:56,237 +Erau cu zecile de mii... +Cea mai mare oștire din această lume. + +45 +00:04:56,274 --> 00:04:57,906 +Ce ai să faci? + +46 +00:05:00,827 --> 00:05:03,995 +Am să sper că nu vor învăța +să se cațere pe Zid. + +47 +00:05:04,030 --> 00:05:06,781 +Dar sticla dragonului... + +48 +00:05:08,168 --> 00:05:09,618 +Ne putem lua adio de la ea. + +49 +00:05:09,670 --> 00:05:13,705 +Oricum n-ar fi contat. +Dacă am fi avut o grămadă cât un munte... + +50 +00:05:13,757 --> 00:05:18,041 +- Dar ai ucis un Umblător Alb. +- Cu Gheara Lungă. + +51 +00:05:19,629 --> 00:05:21,795 +I-am văzut făcând bucățele topoarele +din oțel de parc-ar fi fost de sticlă. + +52 +00:05:21,849 --> 00:05:24,799 +- Dar Gheara Lungă... +- E din oțel valyrian. + +53 +00:05:24,851 --> 00:05:27,385 +Câte săbii din oțel valyrian +au mai rămas în Cele Șapte Regate? + +54 +00:05:27,437 --> 00:05:29,221 +Nu destule. + +55 +00:05:31,925 --> 00:05:35,727 +Primul lord Comandant din istorie +care a sacrificat viețile fraților-jurați + +56 +00:05:35,779 --> 00:05:37,897 +ca să-i salveze pe sălbatici. + +57 +00:05:41,452 --> 00:05:44,535 +Cum e să fii prietenul +celui mai urât om din Castelul Negru? + +58 +00:05:44,571 --> 00:05:46,604 +Ai fost prietenul meu +de cum am ajuns aici. + +59 +00:05:46,623 --> 00:05:48,740 +Și nu câștigam alegeri pe vremea aia. + +60 +00:05:48,775 --> 00:05:51,793 +Atunci, +să închinăm în sănătatea noastră. + +61 +00:05:51,827 --> 00:05:53,544 +Să se tot uite strâmb la noi! + +62 +00:06:01,955 --> 00:06:03,755 +Ce e? + +63 +00:06:06,091 --> 00:06:11,479 +Aș vrea să te rog ceva, +să îți cer ceva. + +64 +00:06:14,434 --> 00:06:17,301 +Trimite-ne pe mine, pe Gilly, +și pe pruncul ei în Orașul Vechi + +65 +00:06:17,319 --> 00:06:19,487 +ca să devin maester. + +66 +00:06:19,522 --> 00:06:25,577 +- Asta e menirea mea. Nu să lupt. +- Am nevoie de tine aici, Sam + +67 +00:06:25,612 --> 00:06:28,029 +Dacă pleci, cine are să mai fie +sfetnicul meu de încredere? + +68 +00:06:29,115 --> 00:06:31,449 +Păi, ar fi Edd. + +69 +00:06:34,319 --> 00:06:36,820 +Ți-aș fi mai de folos ca maester. + +70 +00:06:36,840 --> 00:06:40,792 +Mai de folos tuturor, +acum că maester Aemon nu mai e. + +71 +00:06:40,844 --> 00:06:43,628 +Citadela are cea mai mare bibliotecă +din lume. + +72 +00:06:43,680 --> 00:06:51,101 +O să învăț istorie, strategie, +tainele vindecării și alte lucruri... + +73 +00:06:51,136 --> 00:06:55,689 +Lucruri care o să ne fie de ajutor când... +când vor veni. + +74 +00:06:58,728 --> 00:07:01,395 +Dacă rămâne aici, Gilly are să moară. + +75 +00:07:02,866 --> 00:07:06,234 +Și are să moară și pruncul +căruia i-a dat numele după mine. + +76 +00:07:06,286 --> 00:07:09,486 +Și o să mor și eu, +încercând să-i apăr. + +77 +00:07:11,707 --> 00:07:14,492 +Adică ultimul lucru +pe care am să-l văd pe lumea asta + +78 +00:07:14,527 --> 00:07:17,495 +are să fie privirea ei dezamăgită +că nu i-am putut apăra. + +79 +00:07:22,251 --> 00:07:25,385 +Și mai bine văd o mie de Umblători Albi +decât așa ceva. + +80 +00:07:39,935 --> 00:07:41,985 +Îți mulțumesc. + +81 +00:07:43,523 --> 00:07:45,655 +Știi că și citadela te va pune +să juri că renunți la femei. + +82 +00:07:45,692 --> 00:07:47,942 +Aha, o să încerce ei! + +83 +00:07:51,698 --> 00:07:54,031 +- Sam. +- Ce e? + +84 +00:07:55,667 --> 00:07:57,617 +Sam... + +85 +00:07:59,172 --> 00:08:01,455 +Ai luat o bătaie soră cu moartea. +Cum naiba... + +86 +00:08:01,507 --> 00:08:04,091 +A, cu grijă. + +87 +00:08:05,961 --> 00:08:09,012 +Mă bucur că sfârșitul lumii +a adus cuiva și ceva bun. + +88 +00:08:13,802 --> 00:08:15,887 +O să mă întorc. + +89 +00:08:17,524 --> 00:08:22,025 +- Pentru întoarcerea ta! +- Pentru întoarcerea mea! + +90 +00:10:00,575 --> 00:10:03,909 +Pe aici, mai repede! + +91 +00:10:38,280 --> 00:10:39,946 +Domniță! + +92 +00:10:42,200 --> 00:10:43,700 +Stannis. + +93 +00:10:43,735 --> 00:10:45,869 +Vine Stannis Baratheon +cu toată oștirea lui. + +94 +00:10:45,903 --> 00:10:49,256 +- De unde știi că e Stannis? +- Au pe flamuri inima în flăcări. + +95 +00:10:49,290 --> 00:10:52,876 +De la bătălia de la Apa Neagră. +N-am să-l uit niciodată. + +96 +00:11:30,114 --> 00:11:31,747 +Săpați aici un șanț! + +97 +00:11:31,782 --> 00:11:33,966 +Și altul la 300 de metri +de zidurile castelului. + +98 +00:11:34,001 --> 00:11:36,218 +- Și degrabă! +- Să trăiți! + +99 +00:11:36,254 --> 00:11:37,753 +- Curlew! +- Să trăiți! + +100 +00:11:37,788 --> 00:11:38,971 +Săpați între cele două ridicături! + +101 +00:11:39,007 --> 00:11:40,923 +- Haideți, degrabă! +- Te ajut și eu. + +102 +00:11:40,958 --> 00:11:43,175 +- Arcași! +- Haideți, degrabă! + +103 +00:11:43,227 --> 00:11:48,130 +Și trimite câțiva după hrană. +Începem asediul în zorii zilei. + +104 +00:11:48,149 --> 00:11:50,599 +N-are să fie niciun asediu, Înălțimea Ta. + +105 +00:12:32,059 --> 00:12:34,777 +N-avem nicio șansă! + +106 +00:13:44,180 --> 00:13:46,714 +Nu, rogu-te! + +107 +00:14:39,903 --> 00:14:42,270 +Și femeile luptă în oastea lui Bolton? + +108 +00:14:43,440 --> 00:14:48,944 +Eu nu lupt pentru alde Bolton. +Sunt Brienne din Tarth. + +109 +00:14:51,030 --> 00:14:53,865 +Am fost în Garda Curcubeului +a regelui Renly Baratheon. + +110 +00:15:00,006 --> 00:15:03,709 +Am fost de față când a fost ucis +de o umbră cu înfățișarea ta. + +111 +00:15:06,547 --> 00:15:09,931 +L-ai ucis cu vrăji necurate? + +112 +00:15:15,438 --> 00:15:17,220 +Da. + +113 +00:15:26,149 --> 00:15:30,401 +În numele lui Renly din Casa Baratheon, +Primul pe Numele Său, + +114 +00:15:30,453 --> 00:15:33,453 +Rege de drept al Andalilor +și al Primilor Oameni, + +115 +00:15:33,489 --> 00:15:36,708 +Stăpân al Celor Șapte Regate +și Protector al Domeniului, + +116 +00:15:36,743 --> 00:15:40,829 +eu, Brienne din Tarth, +te condamn la moarte. + +117 +00:15:47,035 --> 00:15:49,252 +Mai ai ceva de spus? + +118 +00:15:58,648 --> 00:16:00,564 +Haide, fă-ți datoria! + +119 +00:16:18,534 --> 00:16:20,700 +Se pare că am terminat aici. + +120 +00:16:36,468 --> 00:16:39,587 +Mă predau! +Mă predau! + +121 +00:16:39,606 --> 00:16:41,606 +Ți eu primesc să te predai. + +122 +00:16:53,436 --> 00:16:57,655 +Hai înapoi! +Sigur nevastă-mea se simte singurică. + +123 +00:17:31,023 --> 00:17:32,440 +Milady... + +124 +00:17:32,474 --> 00:17:34,741 +Am venit să te însoțesc înapoi +în odaia ta. + +125 +00:17:34,776 --> 00:17:37,277 +Mergi cu ea, rogu-te. + +126 +00:17:41,150 --> 00:17:46,286 +Știu cum e Ramsay. +Și știu și ce are să-mi facă. + +127 +00:17:49,041 --> 00:17:51,541 +Dacă e să mor... + +128 +00:17:51,593 --> 00:17:55,094 +Atunci să mor întreagă. + +129 +00:17:57,132 --> 00:18:01,268 +Să mori? +Cine a zis că ai să mori?! + +130 +00:18:01,303 --> 00:18:04,721 +N-ai cum să mori. +Tatăl tău a fost Păzitorul Nordului. + +131 +00:18:04,773 --> 00:18:06,723 +Ramsay are nevoie de tine. + +132 +00:18:09,027 --> 00:18:12,145 +Deși nu cred că are nevoie de tine +întreagă. + +133 +00:18:12,197 --> 00:18:14,864 +Doar de părțile pe care le va folosi +ca să-și facă rost de moștenitori, + +134 +00:18:14,901 --> 00:18:18,034 +până când ai să-i oferi unu-doi moștenitori +și apoi n-are să mai aibă nevoie de ele. + +135 +00:18:19,655 --> 00:18:24,657 +Apoi are niște planuri deosebite +pentru părțile-alea. + +136 +00:18:26,027 --> 00:18:29,914 +Așadar, îl așteptăm să se întoarcă +sau începem acum? + +137 +00:18:31,917 --> 00:18:37,554 +Le lași în seama mea? +Bun. Atunci să începem. + +138 +00:18:39,891 --> 00:18:42,091 +Duhoare... stai! + +139 +00:18:42,144 --> 00:18:44,011 +Înceteazăăăă! + +140 +00:18:50,652 --> 00:18:53,769 +Deschideți poarta! + +141 +00:19:00,830 --> 00:19:02,829 +Se întoarce. + +142 +00:20:37,876 --> 00:20:41,494 +Văd că tu o să-mi dai de furcă. + +143 +00:20:41,546 --> 00:20:43,763 +Voi două, ieșiți! + +144 +00:21:38,152 --> 00:21:41,888 +Ai fost primul pe lista mea, să știi. + +145 +00:21:41,906 --> 00:21:44,940 +Pentru că l-ai ucis pe Syrio Forel. +Ți-l mai amintești? + +146 +00:21:44,992 --> 00:21:47,276 +Probabil că nu. + +147 +00:21:49,329 --> 00:21:52,415 +Pe alții de pe listă i-am dovedit deja. + +148 +00:21:52,450 --> 00:21:55,617 +Zeul cu Multe Chipuri +mi-a mai furat câțiva. + +149 +00:21:55,669 --> 00:21:58,203 +Dar mă bucur că pe tine mi te-a lăsat. + +150 +00:22:01,926 --> 00:22:03,876 +Știi cine sunt? + +151 +00:22:08,048 --> 00:22:10,349 +Ți-a pierit graiul. + +152 +00:22:18,726 --> 00:22:23,146 +Știi cine sunt. +Sunt Arya Stark. + +153 +00:22:32,239 --> 00:22:34,740 +Știi cine ești? + +154 +00:22:37,127 --> 00:22:38,911 +Nimeni. + +155 +00:22:39,947 --> 00:22:42,047 +Nimic. + +156 +00:23:25,659 --> 00:23:27,926 +Fata luat o viață. + +157 +00:23:27,962 --> 00:23:30,429 +O viață ce nu trebuia luată. + +158 +00:23:32,383 --> 00:23:34,265 +Am judecat-o bine. + +159 +00:23:34,300 --> 00:23:35,717 +Într-adevăr. + +160 +00:23:37,437 --> 00:23:39,553 +Nu ești pregătită. + +161 +00:23:41,174 --> 00:23:42,941 +Deloc. + +162 +00:23:46,346 --> 00:23:49,146 +Nu îți era dat ție +să iei viața acelui om. + +163 +00:23:50,651 --> 00:23:52,733 +Fata a furat de la Zeul +Cu Multe Chipuri. + +164 +00:23:54,454 --> 00:23:56,655 +Acum, îi este dator. + +165 +00:24:02,746 --> 00:24:04,578 +Numai moartea +poate plăti viața. + +166 +00:24:17,727 --> 00:24:20,011 +Nu! Nu! + +167 +00:24:20,096 --> 00:24:23,514 +Nu! Nu! +Nu muri! + +168 +00:24:29,106 --> 00:24:30,855 +De ce plângi? + +169 +00:24:32,359 --> 00:24:34,058 +Era prietenul meu. + +170 +00:24:34,078 --> 00:24:36,827 +Nu-i adevărat. +Nu l-ai ascultat? + +171 +00:24:38,164 --> 00:24:40,164 +Era nimeni. + +172 +00:24:42,167 --> 00:24:45,369 +Dar... Dacă ești... + +173 +00:24:48,007 --> 00:24:49,373 +Cine e el? + +174 +00:24:49,425 --> 00:24:51,342 +Nimeni. + +175 +00:24:51,377 --> 00:24:55,046 +Exact cum ar fi trebuit să fie fata, +înainte să ia o față din Hală. + +176 +00:25:01,220 --> 00:25:03,888 +Fețele sunt pentru nimeni. + +177 +00:25:03,924 --> 00:25:05,473 +Tu încă ești cineva. + +178 +00:25:08,528 --> 00:25:12,479 +Iar fețele sunt otravă +pentru oricine e cineva. + +179 +00:25:25,795 --> 00:25:27,328 +Nu pot să văd. + +180 +00:25:33,336 --> 00:25:36,087 +Ce se întâmplă? + +181 +00:25:36,139 --> 00:25:38,255 +Ce se întâmplă!? + +182 +00:25:48,017 --> 00:25:51,186 +- Sper să ajungeți în siguranță acasă. +- Mulțumesc. + +183 +00:25:56,274 --> 00:25:58,742 +Iartă-mă, copilă. + +184 +00:25:58,777 --> 00:26:02,613 +Îți doresc toată fericirea +din lume. + +185 +00:26:19,882 --> 00:26:22,133 +Poate te voi vizita cândva. + +186 +00:26:22,168 --> 00:26:25,769 +- Poate te vizitez eu. +- Să n-aștepți prea mult. + +187 +00:26:25,804 --> 00:26:28,365 +Mă așteaptă o căsătorie cu o femeie +dintr-o familie nobilă acasă. + +188 +00:26:28,608 --> 00:26:32,525 +Vrei o fată cuminte, +dar ai nevoie de una rea. + +189 +00:26:35,648 --> 00:26:37,865 +Plecăm când ești gata, +stăpâne! + +190 +00:26:53,549 --> 00:26:55,965 +Să nu-l pierzi de data asta. + +191 +00:26:57,969 --> 00:27:00,837 +Nu-l voi mai da jos niciodată. + +192 +00:27:00,872 --> 00:27:03,840 +Știu că nu vrei +să pleci din Dorne, + +193 +00:27:03,925 --> 00:27:06,060 +dar mă bucur +că te întorci acasă. + +194 +00:27:06,095 --> 00:27:07,855 +Mama ta e în culmea disperării +așteptându-te. + +195 +00:27:07,880 --> 00:27:12,066 +Și mă bucur că Trystane +vine cu noi, pare un băiat bun. + +196 +00:27:12,100 --> 00:27:17,237 +Ești norocoasă, căsătoriile +aranjate sunt foarte rar... + +197 +00:27:17,272 --> 00:27:19,439 +...atât de bine aranjate. + +198 +00:27:19,525 --> 00:27:21,191 +Crezi că mama-l va plăcea? + +199 +00:27:22,695 --> 00:27:26,080 +Dacă te va vedea fericită, +sunt sigur că da. + +200 +00:27:26,115 --> 00:27:27,447 +Chiar crezi asta? + +201 +00:27:27,500 --> 00:27:32,619 +Știi bine că nimeni nu-i pe placul +mamei tale, cu excepția copiilor ei. + +202 +00:27:32,671 --> 00:27:34,454 +Tu îi ești pe plac. + +203 +00:27:34,506 --> 00:27:37,374 +Nu aș fi așa sigur. + +204 +00:27:37,426 --> 00:27:38,959 +Ascultă... + +205 +00:27:40,929 --> 00:27:43,214 +Vreau să îți spun ceva. + +206 +00:27:44,582 --> 00:27:47,717 +Ceva ce trebuia să afli +de foarte multă vreme. + +207 +00:27:51,890 --> 00:27:54,525 +Acum, după ce ai văzut +o altă parte a lumii, + +208 +00:27:54,559 --> 00:28:00,364 +ai aflat cât de complicate +sunt lucrurile și oamenii. + +209 +00:28:00,398 --> 00:28:03,650 +Casele Lannister și Martell +s-au urât mulți ani, + +210 +00:28:03,702 --> 00:28:05,902 +dar tu ești îndrăgostită +de Trystane. + +211 +00:28:05,954 --> 00:28:08,706 +A fost o pură întâmplare, +sincer, care ar fi șansele? + +212 +00:28:08,740 --> 00:28:12,659 +Să te îndrăgostești chiar de cel care +ți-a fost ales pentru căsătorie? + +213 +00:28:12,711 --> 00:28:14,411 +Vreau să spun... + +214 +00:28:16,631 --> 00:28:19,666 +Că nu alegem pe cine iubim. + +215 +00:28:19,718 --> 00:28:21,968 +E ceva... + +216 +00:28:24,122 --> 00:28:26,622 +Ceva ce nu putem controla. + +217 +00:28:26,642 --> 00:28:28,558 +- Auzi ce spun, parcă-s tâmpit. +- Nu-i adevărat. + +218 +00:28:28,594 --> 00:28:32,461 +Ce încerc să îți spun, +fără să reușesc... + +219 +00:28:32,480 --> 00:28:33,896 +Știu ce încerci să îmi spui. + +220 +00:28:33,932 --> 00:28:36,265 +Nu, mă tem că nu știi. + +221 +00:28:36,351 --> 00:28:37,983 +Ba da. + +222 +00:28:41,240 --> 00:28:43,856 +Știu. + +223 +00:28:43,908 --> 00:28:45,441 +Tu și mama... + +224 +00:28:47,912 --> 00:28:50,280 +O parte din mine +a știut dintotdeauna. + +225 +00:28:52,032 --> 00:28:55,001 +Și mă bucur. + +226 +00:28:58,039 --> 00:29:00,623 +Mă bucur +că tu ești tatăl meu. + +227 +00:29:35,526 --> 00:29:37,460 +Myrcella? + +228 +00:29:39,747 --> 00:29:42,049 +Myrcella? + +229 +00:29:48,389 --> 00:29:51,341 +Myrcella? +Myrcella? + +230 +00:31:09,504 --> 00:31:11,670 +O iubiți, nu-i așa? + +231 +00:31:15,676 --> 00:31:17,810 +Nici nu s-ar putea altfel. + +232 +00:31:17,845 --> 00:31:21,263 +Bineînțeles, e o iubire +fără speranță, pentru amândoi. + +233 +00:31:21,315 --> 00:31:24,851 +Un mercenar din arene +și un cavaler fără onoare... + +234 +00:31:24,902 --> 00:31:27,063 +Niciunul dintre voi nu-i o consoartă +demnă de o regină. + +235 +00:31:29,189 --> 00:31:33,308 +Dar întotdeauna +dorim femeia greșită. + +236 +00:31:33,328 --> 00:31:35,444 +Întotdeauna vorbește +atât de mult? + +237 +00:31:38,282 --> 00:31:40,499 +Jorah Andalul... + +238 +00:31:40,584 --> 00:31:42,751 +Vierme Cenușiu... + +239 +00:31:42,786 --> 00:31:44,286 +N-ar trebui să fie aici. + +240 +00:31:44,321 --> 00:31:45,652 +Nu, dar uite că e. + +241 +00:31:45,672 --> 00:31:48,340 +Regina a ordonat +să fie exilat din oraș. + +242 +00:31:48,425 --> 00:31:50,658 +Regina ar fi fost moartă, +dacă n-ar fi fost el. + +243 +00:31:50,659 --> 00:31:55,113 +E adevărat. Și eu aș fi murit, +dacă n-ar fi fost... + +244 +00:31:58,319 --> 00:32:00,013 +Mărunțelul. + +245 +00:32:00,014 --> 00:32:01,015 +Piticul. + +246 +00:32:01,016 --> 00:32:05,630 +Cred că ăsta-i cuvântul. + +247 +00:32:05,632 --> 00:32:10,139 +Îmi cer scuze, nu mă descurc +foarte bine în valyriană. + +248 +00:32:10,140 --> 00:32:13,218 +O vorbești puțin cam greoi. + +249 +00:32:13,253 --> 00:32:15,950 +Greoi. +Mulțumesc. + +250 +00:32:15,986 --> 00:32:18,703 +Îmi pare rău. + +251 +00:32:18,788 --> 00:32:21,239 +Îmi pare rău că n-am luptat +pentru regina noastră. + +252 +00:32:21,291 --> 00:32:23,241 +Ai ratat o luptă bună. + +253 +00:32:23,294 --> 00:32:24,292 +Nu asta contează acum. + +254 +00:32:24,328 --> 00:32:25,710 +Cu cât stăm +mai mult la taifas, + +255 +00:32:25,745 --> 00:32:28,330 +cu atât mai mult +e Daenerys în sălbăticie. + +256 +00:32:28,365 --> 00:32:30,715 +Are dreptate. +Dragonul a zburat spre nord. + +257 +00:32:30,750 --> 00:32:32,801 +Dacă vrem s-o găsim, într-acolo +trebuie să mergem. + +258 +00:32:32,835 --> 00:32:33,884 +Dacă vrem? + +259 +00:32:33,921 --> 00:32:35,837 +Ești Lannister. + +260 +00:32:35,872 --> 00:32:38,807 +Regina are de gând să înlăture +familia ta de la putere. + +261 +00:32:38,842 --> 00:32:40,542 +Iar eu vreau să o ajut. + +262 +00:32:40,561 --> 00:32:43,178 +De câte zile ești aici? + +263 +00:32:43,230 --> 00:32:44,763 +Eu am luptat +pentru ea ani întregi. + +264 +00:32:44,815 --> 00:32:46,381 +De când era copilă. + +265 +00:32:46,433 --> 00:32:48,682 +- Ai trădat-o! +- Ai grijă. + +266 +00:32:48,717 --> 00:32:51,103 +Iar ea te-a exilat. +De două ori, chiar. + +267 +00:32:51,188 --> 00:32:52,737 +A doua oară +a fost mulțumită ție. + +268 +00:32:52,823 --> 00:32:55,106 +Nu da vina pe mine +pentru greșelile tale, Mormont. + +269 +00:32:55,158 --> 00:32:57,858 +Are dreptate, regina noastră +l-a exilat pe Jorah. + +270 +00:32:57,894 --> 00:33:00,861 +Dar are și el dreptate, +Jorah i-a salvat viața. + +271 +00:33:00,913 --> 00:33:02,913 +Poate acum are altă +părere despre el. + +272 +00:33:02,949 --> 00:33:05,499 +Sau poate că nu. +Doar de la ea vom afla. + +273 +00:33:05,535 --> 00:33:09,204 +Bine, bine, +poate să vină și el. + +274 +00:33:09,239 --> 00:33:11,756 +Dar trebuie să promită +că nu mă va ucide cât dorm. + +275 +00:33:11,792 --> 00:33:15,042 +Dacă o să te omor, o să o fac +când ai ochii larg deschiși. + +276 +00:33:15,078 --> 00:33:17,796 +Iartă-mă, dar de ce +te-am lua cu noi? + +277 +00:33:19,298 --> 00:33:20,631 +Poftim? + +278 +00:33:20,683 --> 00:33:22,767 +Ai luat vreodată urma +animalelor în sălbăticie? + +279 +00:33:22,803 --> 00:33:25,687 +Nu chiar, dar am talente +care pot fi foarte folositoare. + +280 +00:33:25,722 --> 00:33:27,722 +Poți să lupți? + +281 +00:33:27,774 --> 00:33:29,139 +Am luptat. + +282 +00:33:29,191 --> 00:33:30,976 +Dar nu mă proclam +războinic glorios. + +283 +00:33:31,027 --> 00:33:33,060 +Stai bine în șa? + +284 +00:33:33,112 --> 00:33:34,478 +Oarecum. + +285 +00:33:34,531 --> 00:33:36,615 +Deci, în principiu, vorbești. + +286 +00:33:36,649 --> 00:33:38,867 +Și beau... +Am supraviețuit până acum. + +287 +00:33:38,902 --> 00:33:42,237 +Înțeleg, dar nu ne vei fi +de ajutor în această expediție. + +288 +00:33:44,206 --> 00:33:46,240 +Dar ne-ai putea ajuta aici, +în Meereen. + +289 +00:33:47,377 --> 00:33:50,377 +Niciunul dintre noi n-a condus +un oraș, cu excepția lui. + +290 +00:33:50,413 --> 00:33:52,413 +Vrei să-i dovedești reginei +că ai valoare? + +291 +00:33:52,448 --> 00:33:53,781 +Fă-o aici, în Meereen. + +292 +00:33:53,800 --> 00:33:56,584 +E un pitic străin care abia +vorbește limba de aici. + +293 +00:33:56,620 --> 00:33:58,086 +De ce l-ar asculta cetățenii? + +294 +00:33:58,121 --> 00:33:59,970 +Nu pe el. + +295 +00:34:00,056 --> 00:34:01,923 +Dar îl vor asculta +pe Viermele Cenușiu. + +296 +00:34:01,957 --> 00:34:05,643 +Vin cu voi, vreau +să o găsim pe regină. + +297 +00:34:05,678 --> 00:34:08,095 +- Nu poți merge nicăieri în starea asta. +- Ba pot. + +298 +00:34:08,147 --> 00:34:10,432 +Poate, e cel mai dur eunuc +din câți am cunoscut. + +299 +00:34:10,467 --> 00:34:13,602 +Dar nu poți veni cu noi. + +300 +00:34:13,654 --> 00:34:17,154 +Oamenii au încredere în tine, +se știe că vorbești în numele reginei. + +301 +00:34:17,239 --> 00:34:19,106 +Așa-i. + +302 +00:34:19,158 --> 00:34:21,191 +Numai Nepătații pot păstra +pacea în Meereen. + +303 +00:34:21,277 --> 00:34:24,527 +Dacă pleci, +orașul se va autodistruge. + +304 +00:34:24,579 --> 00:34:26,814 +Și Missandei. + +305 +00:34:26,833 --> 00:34:29,784 +Regina nu are încredere în nimeni +așa cum are în Missandei. + +306 +00:34:29,818 --> 00:34:32,586 +Cu siguranță +nu în mine. + +307 +00:34:32,622 --> 00:34:37,424 +Confidenta reginei, +comandantul Nepătaților + +308 +00:34:37,460 --> 00:34:40,177 +și un pitic străin +cu fața brăzdată. + +309 +00:34:41,431 --> 00:34:42,847 +Mult noroc, prieteni. + +310 +00:34:42,882 --> 00:34:44,799 +Meereen e o cetate +antică și glorioasă. + +311 +00:34:44,833 --> 00:34:46,850 +Încercați să n-o distrugeți. + +312 +00:34:48,554 --> 00:34:50,387 +Se pare că am rămas +doar noi, Jorah Andalul. + +313 +00:34:50,439 --> 00:34:52,473 +Hai să ne găsim cai buni. + +314 +00:34:52,524 --> 00:34:54,942 +Avem atâtea de discutat! + +315 +00:35:27,843 --> 00:35:29,844 +Salutări, prieten vechi. + +316 +00:35:31,647 --> 00:35:35,398 +Am crezut că suntem foarte fericiți +împreună, până când m-ai abandonat. + +317 +00:35:37,319 --> 00:35:40,069 +Nu cred că are rost +să întreb cum m-ai găsit. + +318 +00:35:40,106 --> 00:35:44,742 +Păsările cântă și în vest și în est, +trebuie doar să știi cum să asculți. + +319 +00:35:45,995 --> 00:35:49,780 +Mi-au spus că deja ești +agreat de Mama Dragonilor. + +320 +00:35:49,832 --> 00:35:55,918 +Nu m-a executat, să zicem +că e un început promițător. + +321 +00:35:55,955 --> 00:36:00,257 +Acum, eroii au plecat să o caute, +iar eu sunt prins aici, + +322 +00:36:00,293 --> 00:36:03,877 +încercând să împac un oraș +care e în pragul unui război civil. + +323 +00:36:03,929 --> 00:36:05,712 +Ai vreun sfat pentru +un vechi camarad? + +324 +00:36:05,748 --> 00:36:07,214 +Informația e cheia. + +325 +00:36:07,266 --> 00:36:09,850 +Trebuie să afli care-s strategiile +și virtuțile dușmanilor. + +326 +00:36:09,884 --> 00:36:14,388 +Trebuie să afli care prieteni +nu-ți sunt prieteni. + +327 +00:36:14,422 --> 00:36:17,725 +Ce bine ar fi dacă aș cunoaște +pe cineva care are o rețea de spioni. + +328 +00:36:17,760 --> 00:36:19,777 +Ce bine ar fi. + +329 +00:36:21,480 --> 00:36:27,367 +O cetate antică și grandioasă, plină de +violență, de corupție și de înșelăciune. + +330 +00:36:27,402 --> 00:36:33,240 +Oare cine are experiența necesară pentru +a conduce un asemenea dezastru? + +331 +00:36:38,914 --> 00:36:41,164 +Chiar mi-a fost dor de tine. + +332 +00:36:42,334 --> 00:36:44,083 +Știu. + +333 +00:37:05,691 --> 00:37:07,573 +Trebuie să mergem acasă. + +334 +00:37:13,915 --> 00:37:17,033 +Dragul meu... + +335 +00:37:17,118 --> 00:37:19,203 +Doare? + +336 +00:37:21,874 --> 00:37:23,874 +Trebuie să mergem acasă. + +337 +00:37:27,045 --> 00:37:28,461 +Drogon. + +338 +00:37:28,513 --> 00:37:30,762 +Mă poți duce +înapoi în Meereen? + +339 +00:37:34,886 --> 00:37:37,386 +Cât de departe m-ai purtat? + +340 +00:37:45,480 --> 00:37:47,947 +Drogon, trebuie +să ne întoarcem. + +341 +00:37:47,982 --> 00:37:49,700 +Oamenii au nevoie de mine! + +342 +00:38:21,984 --> 00:38:24,016 +Nu avem mâncare. + +343 +00:38:24,051 --> 00:38:27,153 +Ai putea măcar +să vânezi cina. + +344 +00:41:04,644 --> 00:41:06,061 +Mărturisește. + +345 +00:41:09,883 --> 00:41:12,066 +Mărturisește. + +346 +00:41:23,497 --> 00:41:25,447 +Am păcătuit. + +347 +00:41:25,499 --> 00:41:28,282 +Înțeleg acum. + +348 +00:41:28,334 --> 00:41:31,037 +Cum am putut fi așa oarbă +atât de multă vreme? + +349 +00:41:32,923 --> 00:41:35,207 +Vreau să fiu din nou curată. + +350 +00:41:36,426 --> 00:41:38,676 +Vreau mântuire. + +351 +00:41:40,630 --> 00:41:44,433 +Baba m-a vizitat, +ținând felinarul ridicat. + +352 +00:41:44,468 --> 00:41:46,184 +Și în lumina-i sfântă... + +353 +00:41:46,219 --> 00:41:48,720 +Vrei să mărturisești ceva? + +354 +00:41:51,975 --> 00:41:54,391 +Dacă voi mărturisi, +voi fi eliberată? + +355 +00:41:54,477 --> 00:41:57,479 +Înălțimea Ta își va primi pedeapsa +pe măsura păcatelor. + +356 +00:41:59,816 --> 00:42:02,067 +Fie ca Mama +să fie îndurătoare. + +357 +00:42:04,538 --> 00:42:07,155 +Am împărțit patul cu un bărbat +care nu-mi era soț. Mărturisesc. + +358 +00:42:07,207 --> 00:42:08,907 +Numește-l. + +359 +00:42:13,080 --> 00:42:14,495 +Lancel Lannister. + +360 +00:42:14,547 --> 00:42:17,749 +Verișorul tău și scutierul regelui. + +361 +00:42:17,802 --> 00:42:20,668 +- Eram singură și înspăimântată. +- Aveai un soț. + +362 +00:42:20,754 --> 00:42:22,720 +Un soț plecat la desfrânate +de câte ori avea... + +363 +00:42:22,755 --> 00:42:25,640 +Păcatele lui nu le dezleagă pe-ale tale. + +364 +00:42:27,677 --> 00:42:29,761 +Fie ca Cei Șapte să mă ierte. + +365 +00:42:31,932 --> 00:42:33,598 +Au mai fost și alții? + +366 +00:42:34,734 --> 00:42:35,984 +Nu. + +367 +00:42:36,019 --> 00:42:38,235 +Niciunul? + +368 +00:42:39,639 --> 00:42:41,439 +Nu. + +369 +00:42:41,491 --> 00:42:45,025 +Să-nșiri scorneli în fața zeilor +e un mare păcat. + +370 +00:42:45,077 --> 00:42:46,610 +Înțelegi asta? + +371 +00:42:46,645 --> 00:42:48,279 +Da. + +372 +00:42:50,584 --> 00:42:55,285 +Unii spun că pruncii tău +n-au fost zămisliți de regele Robert. + +373 +00:42:55,337 --> 00:42:58,957 +Și că sunt bastarzi născuți +din incest și adulter. + +374 +00:42:58,991 --> 00:43:00,874 +E o scorneală. + +375 +00:43:00,926 --> 00:43:03,178 +O scorneală de pe buzele +lui Stannis Baratheon. + +376 +00:43:03,213 --> 00:43:05,930 +Vrea tronul, însă copiii fratelui lui +îi stau în cale. + +377 +00:43:05,966 --> 00:43:09,217 +De asta pretinde că nu sunt +ai fratelui său. + +378 +00:43:09,269 --> 00:43:11,268 +Mizerabilul. + +379 +00:43:12,605 --> 00:43:14,838 +Nu există nicio fărâmă de adevăr +în spusele lui. + +380 +00:43:14,890 --> 00:43:16,974 +Neg tot. + +381 +00:43:18,612 --> 00:43:20,478 +Bun. + +382 +00:43:21,648 --> 00:43:25,066 +Dar sunt învinuiri cumplite. + +383 +00:43:25,118 --> 00:43:27,734 +Iar regatul trebuie să afle adevărul. + +384 +00:43:27,787 --> 00:43:32,456 +Dacă Înălțimea Ta a mărturisit cinstit, +judecata îți va demonstra nevinovăția. + +385 +00:43:32,491 --> 00:43:34,909 +Judecata? +Dar am mărturisit. + +386 +00:43:34,995 --> 00:43:36,578 +Un singur păcat. + +387 +00:43:36,663 --> 00:43:38,579 +Pe celelalte le-ai negat. + +388 +00:43:38,632 --> 00:43:42,382 +Judecata ta va despărți +adevărul de născocire. + +389 +00:43:44,587 --> 00:43:47,971 +Mă-nclin în fața înțelepciunii +preasfinției tale. + +390 +00:43:49,926 --> 00:43:54,845 +Aș putea cere un singur strop +din îndurarea Mamei? + +391 +00:43:56,982 --> 00:43:59,900 +Nu mi-am văzut fiul... + +392 +00:43:59,935 --> 00:44:02,686 +Nici nu mai știu de când. + +393 +00:44:02,771 --> 00:44:04,605 +Trebuie să-l văd, rogu-te. + +394 +00:44:04,657 --> 00:44:08,443 +Ai făcut primul pas ce te poartă +înapoi pe calea cea dreaptă. + +395 +00:44:10,580 --> 00:44:15,032 +De aceea îți voi îngădui să te întorci +la Fortăreața Roșie. + +396 +00:44:17,286 --> 00:44:19,253 +Mulțumesc. + +397 +00:44:19,338 --> 00:44:21,288 +Mulțumesc. + +398 +00:44:21,341 --> 00:44:22,757 +Mama e milostivă. + +399 +00:44:22,791 --> 00:44:25,043 +Ei ar trebui să-i mulțumești. + +400 +00:44:25,094 --> 00:44:27,094 +O să-i mulțumesc. + +401 +00:44:27,129 --> 00:44:29,379 +Făgăduiesc. +Zi și noapte. + +402 +00:44:31,517 --> 00:44:33,433 +Bun. + +403 +00:44:36,137 --> 00:44:38,972 +Sunt liberă să plec? + +404 +00:44:39,025 --> 00:44:41,358 +După ispășirea ta. + +405 +00:44:43,929 --> 00:44:45,862 +Ispășirea mea? + +406 +00:47:00,416 --> 00:47:03,699 +O păcătoasă se înfățișează în fața voastră. + +407 +00:47:03,751 --> 00:47:07,002 +Cersei din Casa Lannister. + +408 +00:47:08,239 --> 00:47:10,122 +Mama Înălțimii Sale regele Tommen. + +409 +00:47:10,174 --> 00:47:13,459 +Văduva Înălțimii Sale regele Robert. + +410 +00:47:13,511 --> 00:47:19,882 +A păcătuit mințind +și având relații trupești. + +411 +00:47:19,934 --> 00:47:24,520 +Și-a recunoscut păcatele +și a cerut îndurare. + +412 +00:47:24,555 --> 00:47:27,223 +Pentru a-și demonstra căința, + +413 +00:47:27,258 --> 00:47:31,445 +se va lepăda de mândrie și zorzoane, + +414 +00:47:31,479 --> 00:47:34,864 +și se va înfățișa cum au făcut-o zeii. + +415 +00:47:34,899 --> 00:47:37,316 +Înaintea voastră, + +416 +00:47:37,369 --> 00:47:39,952 +oamenii de bine din acest oraș. + +417 +00:47:39,987 --> 00:47:43,406 +Vouă vi se înfățișează +c-o inimă solemnă, + +418 +00:47:43,441 --> 00:47:46,208 +fără de taină, + +419 +00:47:46,245 --> 00:47:50,163 +dezgolită în fața ochilor zeilor +și oamenilor... + +420 +00:47:51,666 --> 00:47:54,884 +Spre-a merge pe drumul ispășirii. + +421 +00:48:15,473 --> 00:48:18,575 +Rușine. +Rușine. + +422 +00:48:18,609 --> 00:48:20,776 +Rușine. + +423 +00:48:22,281 --> 00:48:23,612 +Rușine. + +424 +00:48:23,664 --> 00:48:27,867 +Rușine. Rușine. + +425 +00:48:29,819 --> 00:48:31,536 +Rușine. + +426 +00:48:31,588 --> 00:48:34,708 +Rușine. Rușine. + +427 +00:48:36,461 --> 00:48:38,377 +Rușine. + +428 +00:48:38,429 --> 00:48:42,131 +Rușine. Rușine. + +429 +00:48:43,967 --> 00:48:48,721 +Rușine. Rușine. + +430 +00:48:48,773 --> 00:48:51,357 +Rușine. + +431 +00:48:51,442 --> 00:48:53,225 +Rușine. + +432 +00:48:53,277 --> 00:48:56,060 +Rușine. Rușine. + +433 +00:48:57,781 --> 00:49:01,400 +Rușine. Rușine. + +434 +00:49:01,485 --> 00:49:02,651 +Rușine. + +435 +00:49:04,655 --> 00:49:06,155 +Rușine. + +436 +00:49:06,190 --> 00:49:07,356 +- Lepădătură! +- Rușine. + +437 +00:49:07,375 --> 00:49:08,707 +- Păcătoaso! +- Desfrânato! + +438 +00:49:08,743 --> 00:49:09,909 +- Rușine. +- Desfrânato! + +439 +00:49:09,961 --> 00:49:11,627 +Rușine. + +440 +00:49:11,662 --> 00:49:14,747 +- Desfrânato! Desfrânato! +- Rușine. + +441 +00:49:16,166 --> 00:49:19,803 +Rușine. + +442 +00:49:19,837 --> 00:49:22,087 +Rușine. + +443 +00:49:22,139 --> 00:49:23,973 +- Desfrânato! +- Păcătoaso! + +444 +00:49:24,008 --> 00:49:26,392 +- Lepădătură! +- Te culcași cu frate-tu, ai? + +445 +00:49:26,427 --> 00:49:29,093 +- Scârbă! +- Rușine. + +446 +00:49:30,181 --> 00:49:32,146 +- Marș de-aici! +- Rușine. + +447 +00:49:32,183 --> 00:49:33,598 +Rușine. + +448 +00:49:33,650 --> 00:49:36,352 +- Salut țâțele regale. +- Scârnăvie! + +449 +00:49:36,387 --> 00:49:37,653 +Rușine. + +450 +00:49:37,687 --> 00:49:39,104 +- Pe ea! +- Târâtură! + +451 +00:49:39,156 --> 00:49:40,605 +- Destrăbălato! +- Scârnăvie! + +452 +00:49:40,658 --> 00:49:42,191 +- Scârnăvie! +- Târâtură! + +453 +00:49:42,225 --> 00:49:43,776 +- Rușine. +- Târâtură! + +454 +00:49:43,828 --> 00:49:45,560 +Rușine. + +455 +00:49:45,580 --> 00:49:47,896 +Rușine. Rușine. + +456 +00:49:47,914 --> 00:49:50,865 +- Te culcași cu-n frate! +- Destrăbălato! + +457 +00:49:50,917 --> 00:49:53,952 +Eu am călărit numai jumătate +din câte mădulare a călărit regina. + +458 +00:49:54,005 --> 00:49:56,372 +- Desfrânato! +- Rușine. + +459 +00:49:56,406 --> 00:49:58,507 +- Rușine. +- Păcătoaso! Desfrânato! Târfo! + +460 +00:50:00,261 --> 00:50:02,093 +Rușine. + +461 +00:50:03,680 --> 00:50:06,598 +Rușine. Rușine. + +462 +00:50:06,633 --> 00:50:10,052 +Desfrânato! +Desfrânato! Desfrânato! + +463 +00:50:10,087 --> 00:50:12,137 +Sunt un Lannister. +Suge-mă! + +464 +00:50:12,189 --> 00:50:14,055 +- Suge-mă și pe mine, destrăbălato! +- Înapoi. + +465 +00:50:14,091 --> 00:50:15,306 +- Desfrânato! +- Rușine. + +466 +00:50:15,392 --> 00:50:17,859 +Rușine. + +467 +00:50:17,894 --> 00:50:21,229 +Desfrânato! + +468 +00:50:21,264 --> 00:50:24,533 +Desfrânato! Desfrânato! Desfrânato! + +469 +00:50:24,569 --> 00:50:29,571 +Rușine. Rușine. + +470 +00:50:30,575 --> 00:50:32,457 +Rușine. + +471 +00:50:32,492 --> 00:50:35,209 +Rușine. + +472 +00:50:35,245 --> 00:50:37,962 +Rușine. + +473 +00:50:37,998 --> 00:50:40,082 +Rușine. + +474 +00:50:40,116 --> 00:50:43,117 +- Târâtură! +- Rușine. + +475 +00:50:50,627 --> 00:50:53,061 +Te culcași cu frate-tu! + +476 +00:50:53,095 --> 00:50:57,015 +Rușine. Rușine. + +477 +00:50:57,067 --> 00:50:59,017 +Rușine. + +478 +00:50:59,069 --> 00:51:01,770 +- Scârbă! +- Te culcași cu frate-tu! + +479 +00:51:01,821 --> 00:51:04,188 +- Târfo! +- Rușine. + +480 +00:51:04,240 --> 00:51:06,941 +Rușine. Rușine. + +481 +00:51:08,912 --> 00:51:12,030 +Rușine. + +482 +00:51:12,082 --> 00:51:14,248 +Rușine. + +483 +00:51:14,285 --> 00:51:15,617 +Rușine. + +484 +00:51:16,653 --> 00:51:17,952 +Rușine. + +485 +00:51:22,125 --> 00:51:25,176 +Rușine. + +486 +00:51:25,963 --> 00:51:28,430 +- Rușine. +- Scârnăvie! + +487 +00:51:31,267 --> 00:51:34,636 +Rușine. Rușine. + +488 +00:51:34,671 --> 00:51:37,689 +Rușine. + +489 +00:51:37,723 --> 00:51:41,142 +Rușine. Rușine. + +490 +00:51:41,178 --> 00:51:45,029 +Rușine. Rușine. + +491 +00:51:45,065 --> 00:51:47,650 +Rușine. + +492 +00:51:47,684 --> 00:51:50,652 +Rușine. Rușine. + +493 +00:51:52,688 --> 00:51:55,706 +Rușine. Rușine. + +494 +00:51:55,741 --> 00:51:58,410 +Rușine. + +495 +00:51:58,461 --> 00:52:01,379 +Rușine. +Rușine. + +496 +00:52:01,415 --> 00:52:03,548 +Rușine. + +497 +00:52:08,755 --> 00:52:12,807 +Rușine. Rușine. + +498 +00:52:12,842 --> 00:52:15,677 +Rușine. Rușine. + +499 +00:52:17,897 --> 00:52:19,263 +Rușine. + +500 +00:52:57,469 --> 00:52:59,436 +Înălțimea Ta. + +501 +00:53:05,227 --> 00:53:07,444 +Ce bine că te-ai întors. + +502 +00:53:09,982 --> 00:53:11,648 +Vino. + +503 +00:53:11,700 --> 00:53:13,400 +Te ducem înăuntru. + +504 +00:53:13,435 --> 00:53:15,118 +Trebuie să-ți îngrijesc picioarele. + +505 +00:53:20,326 --> 00:53:25,213 +Am onoarea să ți-l prezint pe cel mai nou +membru din garda regelui. + +506 +00:53:40,763 --> 00:53:44,598 +Dacă n-o deranjează pe Înălțimea Ta, +a făcut legământ de tăcere. + +507 +00:53:44,633 --> 00:53:49,853 +A jurat că nu va vorbi până când +toți dușmanii Înălțimii Tale vor fi morți, + +508 +00:53:49,939 --> 00:53:52,773 +iar răul va fi alungat din regat. + +509 +00:53:59,498 --> 00:54:01,948 +- Cine ți-a sărit în ajutor? +- Stannis. + +510 +00:54:02,000 --> 00:54:03,166 +Acum are el nevoie de tine. + +511 +00:54:03,203 --> 00:54:04,835 +N-avem destui oameni ca să contăm! + +512 +00:54:04,870 --> 00:54:06,621 +Sălbaticii ar putea schimba multe. + +513 +00:54:06,656 --> 00:54:08,039 +Sălbaticii n-ar lupta niciodată +pentru Stannis. + +514 +00:54:08,091 --> 00:54:11,491 +- I-am mai spus asta. +- Le-ai salvat viața. + +515 +00:54:11,510 --> 00:54:13,426 +Dacă vor să trăiască +în Cele șapte Regate, + +516 +00:54:13,462 --> 00:54:17,264 +la adăpostul Zidului, +ar trebui să și lupte pentru ele! + +517 +00:54:17,298 --> 00:54:20,267 +- Nu e lupta lor! +- Deschideți porțile! + +518 +00:54:39,538 --> 00:54:40,987 +Stannis? + +519 +00:54:47,045 --> 00:54:49,997 +Shireen? +Prințesa? + +520 +00:55:44,603 --> 00:55:45,802 +Lord Comandant. + +521 +00:55:45,888 --> 00:55:48,021 +Unul dintre sălbaticii +pe care i-ai adus + +522 +00:55:48,055 --> 00:55:49,689 +spune că îl cunoaște +pe unchiul tău, Benjen. + +523 +00:55:49,725 --> 00:55:51,390 +Spune că e încă în viață. + +524 +00:55:52,978 --> 00:55:55,061 +Sigur vorbea despre Benjen? + +525 +00:55:55,096 --> 00:55:56,980 +A spus că era Prim-Cercetaș. + +526 +00:55:59,117 --> 00:56:01,066 +A spus că știe unde să-l găsească. + +527 +00:56:07,876 --> 00:56:11,578 +Unul spune că l-a văzut pe unchiul tău +la Sălașul Aspru la ultima lună plină. + +528 +00:56:11,613 --> 00:56:13,629 +- Poate că minte. +- S-ar putea. + +529 +00:56:13,665 --> 00:56:14,998 +Dar există moduri de a afla. + +530 +00:56:15,050 --> 00:56:17,049 +- Unde e? +- Acolo. + +531 +00:56:33,651 --> 00:56:35,734 +Pentru Rond. + +532 +00:56:40,442 --> 00:56:41,907 +Pentru Rond. + +533 +00:56:44,645 --> 00:56:45,996 +Pentru Rond. + +534 +00:56:47,698 --> 00:56:49,616 +Pentru Rond. + +535 +00:56:50,985 --> 00:56:53,452 +Pentru Rond. + +536 +00:57:37,214 --> 00:57:38,664 +Olly... + +537 +00:57:46,590 --> 00:57:48,590 +Pentru Rond. + +538 +00:57:48,790 --> 00:57:54,790 +Traducerea: dr.MI, Azael & Kprice +www.subtitrari-noi.ro + +539 +00:57:55,115 --> 00:58:01,115 +Sincronizare: Agentuoo7 +Subtitrări-Noi Team - www.subtitrari-noi.ro + + +540 +0:58:02,000 --> 0:58:07,000 +Subtitrare downloadata de pe +www.RegieLive.ro +Portalul Studentesc Nr. 1 in Romania diff --git a/lab7/sub.srt b/lab7/sub.srt new file mode 100755 index 0000000..a7b4fea --- /dev/null +++ b/lab7/sub.srt @@ -0,0 +1,42 @@ +113 +00:13:30,143 --> 00:13:32,670 +He's a comrade. + +114 +00:13:32,770 --> 00:13:35,632 +He is a soldier. + +115 +00:13:35,732 --> 00:13:40,912 +He's big in business. + +495 +00:43:57,385 --> 00:44:03,316 +I'm telling you, gents. +Informer is this security guard. + +496 +00:44:04,600 --> 00:44:06,294 +Wait >a< second, + +497 +00:44:06,394 --> 00:44:08,537 +I hear what you saying. + +498 +00:44:08,771 --> 00:44:10,798 +But this whole thing is screwed. + +499 +00:44:10,898 --> 00:44:15,636 +The cops obviously know everything. +The job is a flop<. + +500 +00:44:15,736 --> 00:44:20,892 +I'm saying we cancel the job, +finish the cop and piss off. + +501 +00:44:20,992 --> 00:44:23,978 +Let him be killed! diff --git a/lab7/test b/lab7/test new file mode 100644 index 0000000..fe4d617 --- /dev/null +++ b/lab7/test @@ -0,0 +1,284 @@ +/* tic tac toe */ +#include +#include +#include + + +int take_corners(int); + +// explicit instantiation +int moves[9] = {0}; +int moves_made = 0; +int computer_mv = 0; + +enum { human_player = 1, computer_player = 2 }; +enum { top_left, top_middle, top_right, middle_left, middle, middle_right, + bottom_left, bottom_middle, bottom_right }; + +void display_tutorial_board() { + int move; + for (int i = 0; i < 3; i++) { + printf("|"); + for (int j = 0; j < 3; j++) { + move = j + i * 3 + 1; + printf("_%d_|", move); + } + printf("\n\n"); + } +} + +void display_board() { + char mark; + int move; + printf("\n"); + for (int i = 0; i < 3; i++) { + printf("|"); + for (int j = 0; j < 3; j++) { + + move = moves[j + i * 3]; + + if ( !move ) mark = '_'; + else if (move == human_player) mark = 'X'; + else mark = 'O'; + + printf("_%c_|", mark); + } + printf("\n\n"); + } +} + +int _check_win(int x) { + int player_wins = x; + int aux = 0; + for (int i = 0; i < 9; i += 3) { + aux |= moves[i] & moves[i+1] & moves[i+2]; // linii + } + for (int i = 0; i < 3; i++) { + aux |= moves[i] & moves[i+3] & moves[i+6]; // coloane + } + aux |= moves[top_left] & moves[middle] & moves[bottom_right]; // principal + aux |= moves[top_right] & moves[middle] & moves[bottom_left]; // secondary + player_wins &= aux; + return player_wins; +} + +int check_win() { + int player_wins = human_player; + player_wins &= _check_win(player_wins); + int computer_wins = computer_player; + computer_wins &= _check_win(computer_wins); + return player_wins | computer_wins; +} + +int block(int player) { + int move = -1; + + for (int i = 0; i < 9; i += 3) { // blocheaza liniile. + if ( ((moves[i] & moves[i + 1]) == player) && !moves[i + 2] ) { + moves[i + 2] = computer_player; + move = i + 2; + return move + 1; + } else if ( ((moves[i] & moves[i + 2]) == player) && !moves[i + 1] ) { + moves[i + 1] = computer_player; + move = i + 1; + return move + 1; + } else if ( ((moves[i + 1] & moves[i + 2]) == player) && !moves[i] ) { + moves[i] = computer_player; + move = i; + return move + 1; + } + } + + for (int i = 0; i < 3; i++) { //blocheaza coloanele + if ( ((moves[i] & moves[i + 3]) == player) && !moves[i + 6] ) { + moves[i+6] = computer_player; + move = i+6; + return move +1; + } else if ( ((moves[i] & moves[i + 6]) == player) && !moves[i + 3] ) { + moves[i+3] = computer_player; + move = i+3; + return move +1; + } else if ( ((moves[i + 3] & moves[i + 6]) == player) && !moves[i] ) { + moves[i] = computer_player; + move = i; + return move +1; + } + } + + // principal + if ( ((moves[top_left] & moves[middle]) == player) && !moves[bottom_right] ) { + moves[bottom_right] = computer_player; + return bottom_right + 1; + } else if ( ((moves[top_left] & moves[bottom_right]) == player) && !moves[middle] ) { + moves[middle] = computer_player; + return middle + 1; + } if ( ((moves[bottom_right] & moves[middle]) == player) && !moves[top_left] ) { + moves[top_left] = computer_player; + return top_left + 1; + } + + // secondary + if ( ((moves[top_right] & moves[middle]) == player) && !moves[bottom_left] ) { + moves[bottom_left] = computer_player; + return bottom_left + 1; + } else if ( ((moves[top_right] & moves[bottom_left]) == player) && !moves[middle] ) { + moves[middle] = computer_player; + return middle + 1; + } if ( ((moves[bottom_left] & moves[middle]) == player) && !moves[top_right] ) { + moves[top_right] = computer_player; + return top_right + 1; + } + return move + 1; +} + +int try_to_win(int player) { + int move = -1; + if (moves[middle] == computer_player) { + for (int i = 0; i < 9; i += 3) { // tries to make a line in order to not pun random things. + if ( (moves[i] | moves[i+1] | moves[i+2]) == player ) { + if (!moves[i]) { + moves[i] = player; + move = i; + return move + 1; + } else if (!moves[i+1]) { + moves[i + 1] = player; + move = i + 1; + return move + 1; + } else if (!moves[i+2]) { + moves[i + 2] = player; + move = i + 2; + return move + 1; + } + } + } + } else { + return take_corners(computer_player); + } + return move + 1; +} + +int computer_move() { + int move = rand() % 9; + if ( moves[move] == 0 ) { + moves[move] = 2; + } else { + return computer_move(); + } + return move + 1; +} + +int take_corners(int player) { + int move = rand() % 4; + int corners[4] = {top_left, top_right, bottom_left, bottom_right}; + + // prevent the human from playing tricks on us! + if ( ((moves[top_middle] & moves[middle_left]) == human_player) && !moves[top_left] ) { + moves[top_left] = computer_player; + return top_left + 1; + } else if ( ((moves[bottom_middle] & moves[middle_left]) == human_player) && !moves[bottom_left] ) { + moves[bottom_left] = computer_player; + return bottom_left + 1; + } else if ( ((moves[top_middle] & moves[middle_right]) == human_player) && !moves[top_right] ) { + moves[top_right] = computer_player; + return top_right + 1; + } else if ( ((moves[bottom_middle] & moves[middle_right]) == human_player) && !moves[bottom_right] ) { + moves[bottom_right] = computer_player; + return bottom_left + 1; + } + + if (!moves[corners[move]]) { // random corner + moves[corners[move]] = player; + move = corners[move] + 1; + } else { + for (int i = 0; i < 4; i++) { // take first available corner + if (!moves[corners[i]]) { + moves[corners[i]] = computer_player; + return corners[i] + 1; + } + } + return computer_move(); // dumb move + } + + return move; +} + +int computer_move_i() { + int move = 0; + + if ( !moves[middle] ) { // O marks the spot + moves[middle] = computer_player; + move = middle; + return move + 1; + } + + if ( (move = block(computer_player)) ) { + return move; + } else if ( ( move = block(human_player) ) ) { // O is taken, take corners. + return move; + } else if ( ( move = try_to_win(computer_player) ) ) { // force block. + return move; + } else { + return take_corners(computer_player); + } + return move; +} + +int game() { + int choice; + printf("Type a number between 1-9: "); + + int c = scanf("%d", &choice); + if ( c == 0 ) { + printf("\nINVALID MOVE! WATCH IT KID!\n"); + while( (c = getchar() != '\n') ); // clear STDIN + return game(); + } else if (choice < 1 || choice > 9) { + printf("\nINVALID MOVE! WATCH IT KID!\n"); + return game(); + } + + if ( moves[choice - 1] == 0) { + moves[choice - 1] = 1; + } else { + printf("\nWOHO, KID, WHATCHA DOING?!\n"); + return game(); + } + if (check_win()) { + return check_win(); + } + + moves_made++; + if ( moves_made < 9) computer_mv = computer_move_i(); // replace with computer_move for dumb play + moves_made++; + + return check_win(); +} + +void game_start() { + srand( time(NULL) ); + + printf("Hello. Imagine every box is number from 1-9.\nType your number and hit" \ + " enter.\n You are playing X.\n\n"); + display_tutorial_board(); + int winner; + int moves = 0; + + while( !( winner = game() ) && moves++ < 4 ) { + display_board(); + printf("Computer made a move at: %d\n\n", computer_mv); + }; // plays until someone wins or the board is filled. + + display_board(); + if ( winner == 1 ) { // Never going to happen. + printf("Congratulations! YOU'RE WINNER!\n"); + } else if ( winner == 2 ) { + printf("Congratulations! YOU'RE LOSSER!\n"); + } else { + printf("Congratulations! YOU'RE DRAFT!\n"); + } +} + +int main(int argc, char const *argv[]) { + game_start(); + return 0; +} diff --git a/lab7/working.srt b/lab7/working.srt new file mode 100644 index 0000000..673110f --- /dev/null +++ b/lab7/working.srt @@ -0,0 +1,42 @@ +113 +00:13:36,143 --> 00:13:38,670 +He's a comrade. + +114 +00:13:38,770 --> 00:13:41,632 +He is a soldier. + +115 +00:13:41,732 --> 00:13:46,912 +He's big in business. + +495 +00:44:03,385 --> 00:44:09,316 +I'm telling you, gents. +Informer is this security guard. + +496 +00:44:10,600 --> 00:44:12,294 +Wait >a< second, + +497 +00:44:12,394 --> 00:44:14,537 +I hear what you saying. + +498 +00:44:14,771 --> 00:44:16,798 +But this whole thing is screwed. + +499 +00:44:16,898 --> 00:44:21,636 +The cops obviously know everything. +The job is a flop<. + +500 +00:44:21,736 --> 00:44:26,892 +I'm saying we cancel the job, +finish the cop and piss off. + +501 +00:44:26,992 --> 00:44:29,978 +Let him be killed!