consolidate all repos to one for archive
This commit is contained in:
95
semester_5/aturp/naloga_2/main.cpp
Normal file
95
semester_5/aturp/naloga_2/main.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
std::vector<std::vector<int>> vec;
|
||||
|
||||
bool test(int num)
|
||||
{
|
||||
int prev = 0;
|
||||
int count = 0;
|
||||
|
||||
for (size_t i = 0; i < vec.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < vec[i].size(); j++)
|
||||
{
|
||||
if (vec[i][j] <= num)
|
||||
continue;
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
prev = vec[i][j];
|
||||
count++;
|
||||
}
|
||||
else if (count == 1)
|
||||
{
|
||||
if (prev != vec[i][j])
|
||||
return false;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
if (count > 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int alg(int start, bool s, int end, bool e)
|
||||
{
|
||||
if (end - start == 1)
|
||||
{
|
||||
if (s)
|
||||
return start;
|
||||
else if (e)
|
||||
return end;
|
||||
}
|
||||
int middle = (start + end) / 2;
|
||||
bool m = test(middle);
|
||||
|
||||
if (m == e)
|
||||
{
|
||||
return alg(start, s, middle, m);
|
||||
}
|
||||
else if (s == m)
|
||||
{
|
||||
return alg(middle, m, end, e);
|
||||
}
|
||||
|
||||
return middle;
|
||||
}
|
||||
|
||||
int start_alg(int num)
|
||||
{
|
||||
bool s = test(0);
|
||||
bool e = test(num);
|
||||
return alg(0, s, num, e);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
std::ifstream ifile(argv[1]);
|
||||
int size = 0;
|
||||
ifile >> size;
|
||||
|
||||
int num = 0;
|
||||
int max = 0;
|
||||
|
||||
vec.emplace_back(std::vector<int>());
|
||||
vec.emplace_back(std::vector<int>());
|
||||
|
||||
for (size_t i = 0; i < 2; i++)
|
||||
{
|
||||
for (size_t j = 0; j < size; j++)
|
||||
{
|
||||
ifile >> num;
|
||||
if (num > max)
|
||||
max = num;
|
||||
vec[i].push_back(num);
|
||||
}
|
||||
}
|
||||
|
||||
int fin = start_alg(max);
|
||||
std::cout << fin << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
27
semester_5/aturp/naloga_2/makefile
Normal file
27
semester_5/aturp/naloga_2/makefile
Normal file
@@ -0,0 +1,27 @@
|
||||
CC=g++
|
||||
|
||||
CFLAGS= -std=c++23
|
||||
|
||||
INCLUDE_DIR= include
|
||||
|
||||
SRC_DIR= src
|
||||
|
||||
# Get all cpp files from src directory
|
||||
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
||||
|
||||
all: main run
|
||||
|
||||
main: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -o3 -I$(INCLUDE_DIR) $(SRCS) main.cpp -o main
|
||||
|
||||
debug: main.cpp $(SRCS)
|
||||
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $(SRCS) -g main.cpp -o main
|
||||
|
||||
run: main
|
||||
./main testni_primer4.txt
|
||||
|
||||
zip:
|
||||
zip -r main.zip main.cpp $(INCLUDE_DIR) $(SRC_DIR) makefile
|
||||
|
||||
clean:
|
||||
rm main
|
4
semester_5/aturp/naloga_2/solution.txt
Normal file
4
semester_5/aturp/naloga_2/solution.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
test 1: 2
|
||||
test 2: 0
|
||||
test 3: 999492
|
||||
test 4: 999999579
|
3
semester_5/aturp/naloga_2/testni_primer1.txt
Normal file
3
semester_5/aturp/naloga_2/testni_primer1.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
5
|
||||
2 1 8 4 9
|
||||
9 4 1 2 8
|
3
semester_5/aturp/naloga_2/testni_primer2.txt
Normal file
3
semester_5/aturp/naloga_2/testni_primer2.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
8
|
||||
7 7 15 15 2 2 4 4
|
||||
5 5 3 3 9 9 1 1
|
3
semester_5/aturp/naloga_2/testni_primer3.txt
Normal file
3
semester_5/aturp/naloga_2/testni_primer3.txt
Normal file
File diff suppressed because one or more lines are too long
3
semester_5/aturp/naloga_2/testni_primer4.txt
Normal file
3
semester_5/aturp/naloga_2/testni_primer4.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user