From 24ee0f2d8a80f0bdbe4a05972e74bfd955bcbc91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Mon, 11 Apr 2016 20:00:29 +0300 Subject: [PATCH] Initial commit --- lab1/a.out | Bin 0 -> 8808 bytes lab1/lab1.c | 89 + lab2/libstr.a | Bin 0 -> 1312 bytes lab2/main.c | 21 + lab2/makefile | 12 + lab2/my_string.x | Bin 0 -> 8696 bytes lab2/str.c | 32 + lab2/str.h | 10 + lab2/str.o | Bin 0 -> 1076 bytes lab3/a | Bin 0 -> 8868 bytes lab3/a.cpp | 75 + lab3/a.out | Bin 0 -> 9120 bytes lab3/b | Bin 0 -> 9120 bytes lab3/c | Bin 0 -> 8592 bytes lab3/d | Bin 0 -> 8804 bytes lab3/i.txt | 26 + lab3/lab3_1.c | 35 + lab3/lab3_2.c | 120 + lab3/lab3_2b.c | 116 + lab3/lab3_3.c | 35 + lab3/lab3_4.c | 61 + lab4/a.out | Bin 0 -> 13344 bytes lab4/i | 11 + lab4/main.c | 235 ++ lab4/test.c | 22 + lab5/a.out | Bin 0 -> 13540 bytes lab5/tictac.c | 283 ++ lab6/a.out | Bin 0 -> 9064 bytes lab6/a.out.dSYM/Contents/Info.plist | 20 + .../a.out.dSYM/Contents/Resources/DWARF/a.out | Bin 0 -> 8350 bytes lab6/i | 10 + lab6/l6_1.c | 21 + lab6/l6_2.c | 139 + lab6/l6_3.c | 59 + lab6/l6_4.c | 89 + lab7/2.c | 43 + lab7/3.c | 51 + lab7/4.c | 66 + lab7/5.c | 115 + lab7/a.out | Bin 0 -> 9260 bytes lab7/a.out.dSYM/Contents/Info.plist | 20 + .../a.out.dSYM/Contents/Resources/DWARF/a.out | Bin 0 -> 8350 bytes lab7/converted.txt | 284 ++ lab7/dos_2.c | 43 + lab7/dos_3.c | 51 + lab7/dos_4.c | 66 + lab7/dos_5.c | 115 + lab7/g.srt | 2421 +++++++++++++++++ lab7/sub.srt | 42 + lab7/test | 284 ++ lab7/working.srt | 42 + 51 files changed, 5164 insertions(+) create mode 100755 lab1/a.out create mode 100644 lab1/lab1.c create mode 100644 lab2/libstr.a create mode 100644 lab2/main.c create mode 100644 lab2/makefile create mode 100755 lab2/my_string.x create mode 100644 lab2/str.c create mode 100644 lab2/str.h create mode 100644 lab2/str.o create mode 100755 lab3/a create mode 100644 lab3/a.cpp create mode 100755 lab3/a.out create mode 100755 lab3/b create mode 100755 lab3/c create mode 100755 lab3/d create mode 100644 lab3/i.txt create mode 100644 lab3/lab3_1.c create mode 100644 lab3/lab3_2.c create mode 100644 lab3/lab3_2b.c create mode 100644 lab3/lab3_3.c create mode 100644 lab3/lab3_4.c create mode 100755 lab4/a.out create mode 100644 lab4/i create mode 100644 lab4/main.c create mode 100644 lab4/test.c create mode 100755 lab5/a.out create mode 100644 lab5/tictac.c create mode 100755 lab6/a.out create mode 100644 lab6/a.out.dSYM/Contents/Info.plist create mode 100644 lab6/a.out.dSYM/Contents/Resources/DWARF/a.out create mode 100644 lab6/i create mode 100644 lab6/l6_1.c create mode 100644 lab6/l6_2.c create mode 100644 lab6/l6_3.c create mode 100644 lab6/l6_4.c create mode 100644 lab7/2.c create mode 100644 lab7/3.c create mode 100644 lab7/4.c create mode 100644 lab7/5.c create mode 100755 lab7/a.out create mode 100644 lab7/a.out.dSYM/Contents/Info.plist create mode 100644 lab7/a.out.dSYM/Contents/Resources/DWARF/a.out create mode 100644 lab7/converted.txt create mode 100644 lab7/dos_2.c create mode 100644 lab7/dos_3.c create mode 100644 lab7/dos_4.c create mode 100644 lab7/dos_5.c create mode 100755 lab7/g.srt create mode 100755 lab7/sub.srt create mode 100644 lab7/test create mode 100644 lab7/working.srt diff --git a/lab1/a.out b/lab1/a.out new file mode 100755 index 0000000000000000000000000000000000000000..d9732c4435d0ac9da6581a274b1bec6eb827afea GIT binary patch literal 8808 zcmeHMUuaWT7(Z#P*3K;vbaOh{o!X&;)zlWXb7CsJc-`#gv>iIoOOmEdSdx|`ceO%C zgB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/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 0000000000000000000000000000000000000000..0a195941805015ba73b18d37feb35f8de8fc7870 GIT binary patch literal 1312 zcmaJ>QEL-H5Z+5-k|xodAXP!|q=G(Z%+^$TASH)Mxj@CzM5{>MgqRYcNkdF+D}sRr z@d9dpLViLX`xGLTXr9{o?1Kn`Q2HcjQRsE%ZZAn2?FX~p%+BoWw|mE4xS1-Zvtyni zdTlr;bwNWTG99HMS(c=cAccgProrHiP)L&GVXHRjVJr}Ta61wmm*RJ(643|&oWTK5 z1M_kou4in*d$3vlVRF(FGd*rHckFWl0b856tsE8-I58 zT!aXAhy^eQSREY+3~&}~6yyJ3ljjaI^dxB57r|I5vs5yDGfqVBC%Uoaec=xFLoGFE zV8b~FDI-~6EIpqqq|zm}kY9X~f6Ul~alcmnD|eEd>(B(X)M4P7jJ7-t`Z8HITTJCL z<_u#8^@aI4SNQ_5+sBxJZ<)1vAzuU&(eZk4G|qtE{u8XjbGc!-0*wE_Bv>y{AKDSu z-dldazpHBBm1*T(d@`o}QnkN7FdNf8PH4XkSJmFHVc(d%u{c(|UiDVmrI4zx`_EU5 zK8n9F=x?;;t(TI&@mbz_Ay&OHy#*DO_QE&X+#Xod0oyj(R98N@A1aR&HnTn(u-4=L zwAqcTKIdznOVyjO{AVlT(uu0=!h)mgLDYaMZ>n#?LUE_%IBhO61oGh-a7wWET~V3m zFPYqzuk$?KJ)kdt%A6;{^C==MiGt{JxmTeIzvnry+8!QX*KvOX$_eq6?bdPU_{y=j zj(2vfi-7I&I +#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 0000000000000000000000000000000000000000..87a3942993fb4bb340702af87c8b2c2f8a7add37 GIT binary patch literal 8696 zcmeHN+iM(E82@Gyo2%{yq{iAbV=!8M$VFQ)XzQ*dI;%^QnpKNhPxdk~i@Te3FEk5+ zK_hfR1Mv?K5qzv*UnB^oTOz6Pp>0AREEF3=Wkczcp!Gu6-#2?Edr9rH!ujCL`F`iS z%y)ig7S7Dsi+|p@)kLH<5Y4)X$c^?zBhiPXLnFE$%|H`k%=i4rYa=g>@@TDSweYrx z^L!6SA%Y{vg0(Joyr*`IBt~s?mu&1IMAn?ivR0P*d=qzLGB910MKQ*7D$+=^6~Os2 z*<3iYJyf6XX%NDxI;Dq$oq%SUZ=Mz(AJY}XaR-Z2@^F1m388h$OvZKC8CYz2W z-;xgX`A*4v-O|puT558`AVe;CB9@GbSaNdO#F`+~kI z3)atG0%u+8dR|vNbKALvNXA7bp9oLKMJk&{owv{Dq~Yg-;~ioCtJhhGc<4^~Jc#G| zbeVv0bv~}oSyOhY{0;*CBQK5&`<-W4ubU?@%T0UoM4U&e_IM9|X9KM1M9t`$(L2u; zAnCyTY#c*Bfu6Z%dqF2^MSt=^q7?czv@x`5aegP<|C>x8p7YepJs8l@+R^%RnRI_V z7VeMc<56Ii2hg~VcP^jyb~Zir$(P>ID@RX#>UjubpbiBgE81fY<}t{A%$MW%cUUca zAD$=Mc#c}@cUV5Ha&O#!JfF#$iN0t1P)95bC&c&pTu&x=_55=EQoOLd+aIgtugN1Mk5L= z9QvC(tHf?!+is5iBNz}Lux=GUt1--!1J73i=W6W7DuHj;7@mRQEbqmN{m}f@>RI0O z7JF>}71WZ4hT`~^XJGk?_m;ARb*L~EHQV`G@ekm^g7LvO&9D33^oipui;&9v{nl@W z^;huBC9|sH9Tb4?Y>#mwRPxd+SeE-2h1<$wdI@#W2lnMy{b#=I@gxTCY zzA|}de-zbX3|%r7yjuFkYU6$7pi(c-pwxTGzHZpp%eV#>x;{te8!z>KjDB$n7uxy- zWlr%nd+RD|ds*9H4O?W|`W9Mmw3R~P2!*0(;YgHx$&emOn|i`bn|&r+1M_)r3mU{*Kd$4%dnZ?59vq2;O;QAmI4X#ds!f-(LeAQhSH)S69V?3h F{sBDivtIxJ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..4b9d1384aae76d781c431f86ca033eb3b6020f17 GIT binary patch literal 1076 zcmaJ=&ubG=5PqA)BsHkt{}efgXzXhfwqx(v%8K3~_5)5ezhl z8&LZv^iRmKr;t)fn^RlQ9;6@$r6)m)g>Juj`<84Cc3|e4c{B69nU~G>--F`_V_J~G zKts?5ISDA_8uTv3|B)S)`xn8S&R?Jj##e#bx#Oe9c zYR?tbV03xpNsO^skBjgI)F3Bzo~+#ADsT&Zv{w{n2#7v53iS)kM|#Gy`^!)HpKqJFU9OP-Useq2tQmt_bK!_NOc+Lp{i4J zFy_^{U6OB(e3#Bq^Yqlwo%j}pFDgs}F-|z45FlgvwshY%?_9~ aw74W*S(SWw$#Y9SKVK{}O3xKajGX{EaH|3U literal 0 HcmV?d00001 diff --git a/lab3/a b/lab3/a new file mode 100755 index 0000000000000000000000000000000000000000..efcfee28f0028f183d339fe792ddfbe8e7ab5d7c GIT binary patch literal 8868 zcmeHMUuauZ7(a1c*VWWyAX4|o#bIR@O?P`_B2!x#8q|SMU73vPlTv1|jAi5<&z}MmGv^N`%l7;&BucMat2k*NwN0LvOOT zm3*!6o``mK!-14z#?i4>6*WHC+9x!|+ytg0+O=59LgGZBq3gC6?ZRRpKCdT5+}2Ph zm}`bo<_pE~{92dW-V+E2O+BSG9PA9}(DoYhqdl2QWO4}$N^X0@+TMsZK+L$W(YpD? z^93uNozx0$dkfm0vqs`(YOxK0l*R0O>Fk6|XOq(kx9-O$+8+0uMC`Uvm(*)16DgUr zVp9nRx7u6Q_PX^TVw|=663@vX0xsq7(AZFu8qR~-Qsi(LBwu*j*N0CGqHc0U$?f`Ph}8s zvpueNvy#-S#&;dem!4As}t0Y0c@WD($_ z;Ag<2;54K5_DLb|sR=&}oB@9rWfY~E_#Lw}$Dvuy_BGhS5m`r%peKalN9il(t-efp zyl-MAGXYH6hQfK2|NOiB#oqq#+|Os1R;;gY@w-LnFriLWdL7I@&~B`k;}+?liRfn# zg)*+u*ZDm@F<-+s{2!jl7ZOw9y8jK%`%^2m#T7XdE7`qeDW-Y`o=+bkDv+zbTU!R=%q+#Wd1TgGMMt`Ds894fPHP=nkC?|{~o zHLX=ph4(d#KrPC~-D4M({gc(uz+!0$eroUoUsvrYY?dyRez6ataoMPHfEhQc<{sll z;A9xc9)RQ#PqWKr={Df9eH{ws$xESQ7n8|kII#0$U?H6OIdi+`RLuET+u%&iuY3R#2(~Sq z_1UygGHmx$>P`YX=bG$C&hcVd`p%r6y=IoXUZ%D3X0vplcG>uWdiGB%SVTj~j;m#K z`L*Vr1GT^@u5n-y_9MqG+8njo^M|T$sk)}>JF4amtoE#+7Gh+6$G2cZhgW;P1Ybz8 zv+^4pqih z7XdEK&V8v=y zcaaTZc`Gt?)45_M2Hlut#b(5QFfqD8EN-KGJF3MUI@Zfuqo4Vr_1s>-r!s`<<>WEQ z19%@{K9J8Oe19R1YP`#l;~j?b=N-AmuK=T;B1L@IX~xopCtWz}!UY%pz=c0@VZLzj zjgU`S%nu{$sdBM?a8QIf?fdD3kdfSTbBv|TwFX$~y=XZ*>IAg()K8Oh9P~k` Q9|67j^=)5w)YP2CKiXCB+W-In literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..1918d4f0d383369d4244e8c768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+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 0000000000000000000000000000000000000000..b03d34010ddc4f5585452cc0502397c5c73b70cb GIT binary patch literal 13344 zcmeHOZE#%GdA@7QL>9&?h}&_fTW*L9PH=<_ZbybukYe58x=0{9aw1Zj^?G;Z-9aDA z?utlhJe9k?8696XRRGO+0&P4KhM1Heo{l#W8LO2+VFg2j(mIZRFs;gv^r}@_B_&e< zZq(;F=j^9MTK7kP?H%27-p}WK&wI{2d-v|uoA3Yp*B>zq-+IFsU1u1EAE&XwFdV}q zWqb^$jWZDFYP;Y1qIKXQO3M#lIlCrDoGUO41iG!B?s609Z4^UiPy!!KsCHY>B-kTK;Z?V zk-m5&0a+#9vc@~2?a8z5g=1BIp=2r%8#ty7D)D-@sr&+%Kpx~vk1}j10)e4{FU1DJ zf!ILrpybQvWAYY-$2sRgz7j)eRLgm7mh;-)*4ExyKt5sl;zJ-c`5DPWf=NWD-|1?!I?NY z<~xUyi97pZNAC=e^o7Cmz_OQlY4$=c8YbeLdYX|MuTEKweLS>rs82pUU%; z;n;!UF#kCwUve-`GfwI_Mql0QsF<%98}UCkl1xSV8$a8KJYq*-gyS}xj5myWu>Yjy zS)b}rt-!Tb;GivjYK!B`cKZ0T;eUF%!RP<(^x;=}{kNQyP}J{&pp>`Mi}kixerY!> z#Ot;gTDD!B=~ruQVJ&%kaDCaXwPdGf>VYJW#xj4#b9sJbZGC#tv@=%yORYM<@g-aQ z1laT5Pd*B4VR=Z`GyKjCFtBshGCE_S5zVB`>1EsPgvrHPvzXYu`&m4$b)E!&yn(~RjIhv_M6x?#Ql zyR+%{PyucWcBZ8T_U8<5<|b)7MqA-{aQ7a7hn<<~T3K0fhn~R5mqqp+C~WaV?@p;} zxe3nhL=P>b3P67hAmPk2en`fj+6uKy;r;(Y3JzJFh0pIisj|2XFF1cjW-&ESbeYIo zOyp(wA(69?x>--^n9CKN%eSPu<*V>@C(cVFssQ)zH*!!@@dDf>!X=gcdrHC0p>wm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Yb6)y55-5w+2D#^UF3#Rp=gj16Fp#)q2K@!^M@~h z{}I?2=#K^>!;#QXDuQ?LgUqlimW=erQzJ&V>K>-tcqGOA_}nUKM8gr;_s0`PqCXfL zFkbNSIm&utZZn!CHluztcok~BF)thZVzCZmGRAy^p-3``*Xfa;@tn_C*B48sjBoe? z!9*fBVtf<-SuuSh0d7XKbPJlfPXl{yvsvG2j{1&F*Dh_Czd^pU?Dz3^5cN=ouQ&Vg zkY^sxa`Ml5$REMaRpcAAKCbn5Xns`lyELEwe~5cD&-bS3->P{7FL{vf)cmx@=b~V| zB|Ofi{#ahG@%zC;PL(|V1Z^q*WCj1{75wuR{EHR*`3n9*1wT{4|7`_-se +#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 0000000000000000000000000000000000000000..ddc7367a467c6900429bbae9d8afe66572e57b33 GIT binary patch literal 13540 zcmeHOeQ+Da72mTXi0x20G=cDyoG}JNgOjvCAs=8Tz955TyNR6y7<$OEVry(m9({zk z#jP3P8H>Y=X@@D4GI)j#Wjg&x3DAaiASN^p87QXB6v~9w(}tpJ-Kj_f5g_9J-tL}s zl3o67|Ip6t$J_U@@4bDyx3?#~@yWl=oXwb0%GhuTW6X&>;b3fpsc12F0kR8O*V`Iy z)^69fwNh_>Qu4tCA(B&z0d&1x+tr>=!ui$wJ~=#tZVc+Mvm{#ABfh0P`ea ziW9_eR##mQ^y%Tj{?1^ZJ`f50S9z8=rV4&869vsD$+VKLcL#G`o3CG`D)d_{83-nQ ztVHt4EC98x_jx`~zZI&GcfI5x*e;KBE0;K`XkPpKg8{3n(0^^Jkhj_*Ky9B_89rGo z&4XC?%}p)0YK=|Snq6Bk4}dA1kitkWyR1tY8|EY^$Ty2oTQ(72J>VYHPoq}BNU^a3 zd1js1d!GFYV{6f0fxb3md#VIL+3r_6p4tQ8Us~7+n6?KMc?t5GXgIW{&)>PGYp|~i zFr|x-NspSx_CIv|+#BC{toD~npJxeR?YCaZw=k!fGxF!dqT!d~K=z`C|48i(vA z9NDOpABD%1+}Id@`(QZY>#y5f2R;0qAVRtvndBdVKZy5A36p<{spx^C2Z|mjdZ6fm zq6dl|D0<-k&jTH<_UF0}l_Rl(N?gkr(F}N&0}zaSyP>>>bZUKp^Pz~N_i3hlG45*oL}A4Ap3-HkOR@ zAi#KktX?v{!41ybD#bRA!YX<@gPv#0&Z$MC+@Ovm1xiOM_OcT1$e8b=l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hV64T3hMD5>NNijt9t13 zf_a=;S5WKs)Vh{hN2t|6trw})Lak@1bqBS6jMhC&uj$h7VddrcD5ckU(QF?a@Tnd( z5bf{uh15=80;$gEjt>Tn;KPj>kh3--PzE-#icg2tG6~aRzb+l zR#)q40#>U#U4&~;8(W)NZoUafm#?ocSf@7id%FDrpX%G=3k|BB!M&dLtqgTZLXLU{sRYL7pn`T`MOsIFYSEf`fjA)h+X=NZIjR&`e$jMx(FABY04_ItX> zivHjpRFU;+O&7-ox~(|2l0)J6p3JC}m*NW{%kwqbS5tFZwP zQMs&_$$F)%Yi0dqS#Ol}JUPXVq6dl|D0-mifuaYB9w>UC=z*dKiXJF>py+|32Z|o} zpL<~Gr7P%?nk}u@>8J1>Z?Ep{>D9ZVo=_M2TBvfoo_-X|ebm@4x~tLIHZS`|XJ63U%N|i8>~W>r1JXY${pHX{w{xUIL4U+N8KoT0%BS9|vfa2-(;m6pafG-qgFM?`jH3?b+D%>KmH zdnFKmjiUS6pMXzZ1N^@06mowk!e-GmaRaD5&~%u1!fXT#6B|G_U9aeLC&j*lo>V=0 z()DBuRGv^~l%!HWy?D5EV$r}sC0Q~IGs#jXE^=ln#eEJw-U9}JME5(FA``w6pO*-} zQo_@?qa>K_j|k5$6z~=a4@kJ3U|d-3RR!K7@${o*VjGaK^}mc!39r3K;2)Im1TM3P z{`(e;`zwMc2!{MNRlq-za74oU2?pT|zDyAPq=fIn%`3t5kq0$3dHM@VJAASL{`q#IS_$p>)69|YmJE&kp&ADjLugaFJ +#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 0000000000000000000000000000000000000000..0bc74d93d349a593431d2d483de6d37bb32105a1 GIT binary patch literal 9064 zcmeHNZ){sv6~C`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HO zRsAj1Z&AM!?>4W>uOd)Ipo%~hfhq!31gZ#B5vU?iMWBj66@e-ORRr!I1hze9h?l}` z2RJ>22SXz~G(5tGCW2O&J#VpD$qz>?D*=LD+{BAHAH<_CUbtsfD3(!SAsUR0LTWXG zA5GxJITaoqvo@Y+l2?_wcc6nWa8wsxLYAFbWOZGid&b51dZE9ysweM6N;vH zN1|I5?fm}*x`EdrSjM9e$?1ZW=mK6Gh#pY%Yl@~@N|N^~`==B=t>%9nG{iJjlvmNZ z>9ZB|TNU&|1-(>3U#XxGmUyeBYbbiV#nqK~6Q+AilmnG=125ut?m4g6WG?m?yN*my uJ1mLP-b%W-pIoMkqbw + + + + 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 0000000000000000000000000000000000000000..d0f53c3ad954c1fb085aee50d817b9cb6c0d1ff0 GIT binary patch literal 8350 zcmeI1J#Q015Qf)I0^u_*PykVI1+pk8QW{Y?vcV1rqF{-LW^_Jp93%T|ozFN)m5vf5 zDjLL3NI^wKLxF?@9hCe5BswGtU}kUD-dmes(IBB6X>WG+So9JAV!0EKN7}rvIGA`JXd>IZ zu8^M>`(_Bxj|cVssLAHNK9%rDGi~O27nwKCk9e>x+dUcK1e^DXc?AtaPuh=cBEO&; z_QwmhdAZX`ex`h>^^U+v1t93hQ7de6yUp{M_t;#d!ARwb?Er&t*a{oa3b(o{PCws+ zr6fPvL)vVHZYNLsq=5GZC>3i(qX!qLQZg56bkpOeJx_%UpxGU(_IsX*({pJ)Jx^0d zfUphy-A=vRhF%;^e;ChWo=1b(%=~D*i@F2-_&vQs_J*l zvvlJG&+_vn4p$Xz{GOKX6*sP{Hg#FCI9}5AoJVN=^%?;hvOZ{nU#~~bYLsRjVQ*K11%{f?x!-{xhRcZp|Zz0~xHAjRwXfz8WX zy!?#3c(*q-zcuEeQ?@oEuUmf*&;&cbJuAPxKk$g*%qid$a0)mDoB~b(r+`!7-zz|8 ztEEg%B|_iA%PJP)01pck=Q&=%Lq5eVEvNr+Aa&7aVVKyw3a~ z$NM~=zBD`AAa`Uih$Wtj{RW}+z zV;HrNrw1pIF*<1&4acmUIR%^oP64NYQ@| + +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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undlePackageType + 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 0000000000000000000000000000000000000000..fabbb14697d97d44c208b49a279118d58a4434be GIT binary patch literal 8350 zcmeI2L2DC16vt=NR%5L;UZkR64ib74JXrK%ps{I{T53QM;klb^l9k=fvOCc>c<49q z3y660B7Oj`egLl?yy-y?f*^u;P~Y2~-E5{w4L!5%GAu-#DZEDgAT`0Mg!(!$_UCN0Z0yD>MmZ zvuT6sS+SRQ0V3JAqU@5+dvhY;+xbS$?tv+qcd_{@%~te*LAhp zsOEZbJ!72?SXbJkRLB52z1*^*Kb}`i!sE|$EIFhw$e@hVgDKuDc z`QPvWK>f?g-@+dY$iJ%mYsV6QP5J4$nw~_xF4#MEvoCEt=b9}%=YnTCzJS0CBfKU( z7u#X4X-5%6eM>sh#fM^ux=veybUa(YppA!6WV5jXtN<&(3a|pK04u->umY?AE5Hh{ w0<6Gc6sX^>*6Acqg=`_IV&A~`eSgpn6GQ(RAfvbG#F@c&@^j)iwx(zP1;IzajQ{`u literal 0 HcmV?d00001 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!