Skip to content

Commit

Permalink
study
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtDu committed May 28, 2019
1 parent 945134e commit 8ccb005
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 8 deletions.
Binary file added books/sedgewick_5.djvu
Binary file not shown.
8 changes: 0 additions & 8 deletions labs/lab_6/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@


#include <iostream>
#include "TLongInt.h"


using namespace std;

int main() {

std::string str1, str2;
Expand Down Expand Up @@ -65,9 +60,6 @@ int main() {
std::cout << "Error" << std::endl;
break;
}


}

return 0;
}
14 changes: 14 additions & 0 deletions labs/lab_7/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CC = g++
FLAGS = -std=c++11 -g -pedantic -Wall -Werror -Wno-sign-compare -Wno-long-long -lm
SOURCES = main.cpp
EXECUTABLE = main
all: build

build: main.cpp
$(CC) $(FLAGS) -o $(EXECUTABLE) $(SOURCES)

main.o: main.cpp
$(CC) $(FLAGS) -c main.cpp

clean:
rm -f *.o
Binary file added labs/lab_7/da_lab7.pdf
Binary file not shown.
36 changes: 36 additions & 0 deletions labs/lab_7/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <string>

int64_t matrix[101][101];

int64_t getCount(std::string &str, int i, int j) {

if (i == j)
return 1;

if (i > j)
return 0;

if(matrix[i][j] == 0) {
if (str[i] == str[j]) {
matrix[i][j] = getCount(str, i + 1, j) + getCount(str, i, j - 1) + 1;
} else {
matrix[i][j] = getCount(str, i + 1, j) + getCount(str, i, j - 1) - getCount(str, i + 1, j - 1);
}
return matrix[i][j];
}

return matrix[i][j];

}


int main() {

std::string str;
std::cin >> str;

std::cout << getCount(str, 0, str.size() - 1) << std::endl;

return 0;
}
10 changes: 10 additions & 0 deletions labs/lab_7/test_code/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CC = g++
FLAGS = -std=c++11 -Wextra -Wall -Werror -Wno-sign-compare -Wno-unused-result -pedantic -O2
FILES = TSuffixTree.cpp main.cpp
PROG = lab5

da5:
$(CC) $(FLAGS) -o $(PROG) $(FILES)

clean:
rm -f *.o lab5
88 changes: 88 additions & 0 deletions labs/lab_7/test_code/test_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!usr/bin/python

import string
import sys
from random import *


def get_random_num():
return ''.join(choice(string.digits) for _ in range(randint(1, 100)))


def get_num_pow_num():
return ''.join(choice(string.digits) for _ in range(randint(1, 1)))


# <count of tests> <count of nums in test>


if __name__ == "__main__":
if len(sys.argv) < 3:
sys.exit(0)
tests, numsInTest = int(sys.argv[1]), int(sys.argv[2])
for i in range(tests):
test_file_name = "tests/{:02d}".format(i)
with open("{0}.t".format(test_file_name), 'w') as output_file, open("{0}.a".format(test_file_name),
'w') as answer_file:
for _ in range(numsInTest):
op = choice('^')

ttext1 = get_random_num()
if op == '^':
ttext2 = get_num_pow_num()
num1 = int(ttext1)
num2 = int(ttext2)
output_file.write("{0}\n".format(ttext1.lstrip()))
output_file.write("{0}\n".format(ttext2.lstrip()))
output_file.write("^\n")
if num2 == 0 and num1 == 0:
answer_file.write("Error\n")
else:
answer_file.write("{0}\n".format(num1 ** num2))
else:

ttext2 = get_random_num()
num1 = int(ttext1)
num2 = int(ttext2)
output_file.write("{0}\n".format(ttext1.lstrip()))
output_file.write("{0}\n".format(ttext2.lstrip()))
if op == '+':
output_file.write("+\n")
answer_file.write("{0}\n".format(num1 + num2))
elif op == '-':
output_file.write("-\n")
if num1 >= num2:
answer_file.write("{0}\n".format(num1 - num2))
else:
answer_file.write("Error\n")
elif op == '*':
output_file.write("*\n")
answer_file.write("{0}\n".format(num1 * num2))

elif op == '=':
output_file.write("=\n")
if num1 == num2:
answer_file.write("true\n")
else:
answer_file.write("false\n")

elif op == '>':
output_file.write(">\n")
if num1 > num2:
answer_file.write("true\n")
else:
answer_file.write("false\n")
elif op == '<':
output_file.write("<\n")
if num1 < num2:
answer_file.write("true\n")
else:
answer_file.write("false\n")
elif op == '/':
output_file.write("/\n")
if num2 == 0:
answer_file.write("Error\n")
else:
answer_file.write("{0}\n".format(num1 // num2))


44 changes: 44 additions & 0 deletions labs/lab_7/test_code/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# *.sh <count of tests> <count of nums in test>

fail=false

if ! make -C ../; then
echo "ERROR: Failed to compile file."
exit 1
fi

if [[ $# -ne 2 ]] ; then
echo "ERROR: Failed in args."
exit 1
fi

mkdir -p tests
if ! python3 test_gen.py $1 $2 ; then
echo "ERROR: Failed to python generate tests."
exit 1
fi

for test_file in `ls tests/*.t`; do
answer_file="${test_file%.*}"
echo "Execute ${test_file}"
if ! ../main < ${test_file} > "${answer_file}.my" ; then
echo "ERROR"
continue
fi

if ! diff "${answer_file}.a" "${answer_file}.my" > /dev/null ; then
echo "Failed"
fail=true
test=${answer_file}
else
echo "OK"
fi
done


if $fail ; then
printf "\n"
echo "ERROR in $test"
fi

0 comments on commit 8ccb005

Please sign in to comment.