-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
192 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |