106 lines
2.8 KiB
C++
106 lines
2.8 KiB
C++
#ifndef NALOGA0702_SABLONE_H
|
|
#define NALOGA0702_SABLONE_H
|
|
|
|
#include "PrintUtility.h"
|
|
#include <vector>
|
|
#include <sstream>
|
|
|
|
template<ColorCode C = ColorCode::Green, typename T>
|
|
void print(const std::vector<T> vector) {
|
|
for (int i = 0; i < vector.size(); ++i) {
|
|
PrintUtility::print(C, vector[i].toString());
|
|
}
|
|
std::cout << "\n";
|
|
}
|
|
|
|
template<ColorCode C = ColorCode::Green>
|
|
void print(const std::vector<int> vector) {
|
|
for (int i = 0; i < vector.size(); ++i) {
|
|
PrintUtility::print(C, std::to_string(vector[i]));
|
|
std::cout << " ";
|
|
}
|
|
std::cout << "\n";
|
|
}
|
|
|
|
template<unsigned int N, typename T>
|
|
std::vector<std::vector<T>> slice(std::vector<T> vector) {
|
|
std::vector<std::vector<T>> retVec;
|
|
std::vector<T> ret;
|
|
int count = 0;
|
|
for (int i = 0; i < vector.size(); ++i) {
|
|
if (count < N) {
|
|
ret.push_back(vector[i]);
|
|
count++;
|
|
}
|
|
if (count == N) {
|
|
retVec.push_back(ret);
|
|
ret.clear();
|
|
count = 0;
|
|
}
|
|
}
|
|
retVec.push_back(ret);
|
|
return retVec;
|
|
}
|
|
|
|
template<typename T>
|
|
std::string toSafeString(std::vector<T> vector, std::vector<T> prepovedano) {
|
|
std::string ret;
|
|
bool prepoved = false;
|
|
for (int i = 0; i < vector.size(); ++i) {
|
|
for (int j = 0; j < prepovedano.size(); ++j) {
|
|
if (vector[i] == prepovedano[j]) {
|
|
prepoved = true;
|
|
}
|
|
}
|
|
if (prepoved) {
|
|
for (int k = 0; k < vector[i].length(); k++)
|
|
ret += "*";
|
|
} else {
|
|
ret += vector[i];
|
|
}
|
|
ret += " ";
|
|
prepoved = false;
|
|
}
|
|
ret += "\n";
|
|
return ret;
|
|
}
|
|
|
|
template<typename T>
|
|
std::vector<T> reverse(std::vector<T> vector) {
|
|
std::vector<T> ret;
|
|
for (int i = vector.size() - 1; i >= 0; i--) ret.push_back(vector[i]);
|
|
return ret;
|
|
}
|
|
|
|
template<typename T>
|
|
double sum(std::vector<T> num) {
|
|
double ret = 0;
|
|
for (int i = 1; i < num.size(); ++i) ret += num[i];
|
|
return ret;
|
|
}
|
|
|
|
template<typename T>
|
|
void printSelectedWordInColor(std::vector<T> vector, std::string printColor) {
|
|
for (int i = 0; i < vector.size(); ++i) {
|
|
std::string str = vector[i].toString();
|
|
std::string word;
|
|
std::stringstream iss(str);
|
|
while (iss >> word) {
|
|
if (word == printColor) {
|
|
PrintUtility::print(ColorCode::Blue, word + " ");
|
|
} else {
|
|
std::cout << word << " ";
|
|
}
|
|
}
|
|
std::cout << "\n";
|
|
}
|
|
}
|
|
|
|
#endif //NALOGA0702_SABLONE_H
|
|
|
|
/*
|
|
* std::size_t pos = word.find(printColor);
|
|
std::string str1 = word.substr (0,pos);
|
|
std::string str2 = word.substr(pos,printColor.length());
|
|
std::cout << str1 << "||||" << str2 << "\n";
|
|
*/ |