#include <iostream>
#include <string>
#include <vector>
std::vector<std::string> split(std::string str, char delimiter) {
std::string tmp{""};
std::vector<std::string> vec;
for(int i{0}; i < str.length(); ++i) {
if(str[i] == delimiter) { vec.push_back(tmp); tmp = ""; continue; }
tmp += str[i];
}
vec.push_back(tmp);
return vec;
}
int main()
{
std::string s{"name^age"};
std::vector<std::string> res = split(s, '^');
std::cout << "Result is: ";
for(auto i : res) std::cout << i << ' ';
return 0;
}
const arr = ['Jimmy', 'Rayn', 'Jack', 'Vladimir', 'joen'];
let res = arr.filter(el => /J/i.test(el[0]));
console.log(res);
let arr = ['Андрей', 'Алексей', 'Сергей', 'Антон', 'Матвей', 'Роман', 'Руслан'];
let arr2 = [27, 22, 38, 45, 51, 42, 19];
let res = [];
arr.map((el, i) => [arr[i], arr2[i]]).sort((min, max) => min[1] - max[1]).map(el => {
let ob = {};
ob[el[0]] = el[1];
res.push(ob);
});
console.log(res);
#include <iostream>
#include <ctime>
void fillRandom(int* arr, int size, int min, int max) {
for(int i{0}; i < size; ++i) {
arr[i] = min + (rand() % ((max - min) + 1));
}
}
int main() {
srand(time(NULL));
int len{10}, min{10}, max{99};
int array[len];
fillRandom(array, len, min, max);
for(int& i : array) std::cout << i <<' ';
return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
void fill_random(std::vector& v, int min, int max) {
int i{0};
auto lambda = [&](int index){ v[i] = min + (rand() % ((max - min) + 1)); ++i; };
std::for_each(v.begin(), v.end(), lambda);
}
int main() {
srand(time(NULL));
int size{10}, min{10}, max{99};
std::vector<int> vec(size);
fill_random(vec, min, max);
for(int& i : vec) std::cout << i << ' ';
return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
int main() {
std::string str{"This string in file"};
std::stringstream s(str);
std::vector<std::string> vec;
std::string word{""};
while(s >> word) vec.push_back(word);
for(auto &i : vec) std::cout << i << '\n';
return 0;
}
#include <iostream>
#include <regex>
#include <string>
#include <vector>
int main() {
std::string str{"Hello! This string of your file"};
std::regex reg{"\\S+"};
std::vector<std::string> vec;
std::smatch sm;
while(std::regex_search(str, sm, reg)) {
vec.push_back(sm.str());
str = sm.suffix();
}
for(auto &i : vec) std::cout << i <<' \n';
return 0;
}
#include <iostream>
#include <string>
#include <vector>
void split(std::string& str, std::vector<std::string>& vec) {
std::string tmp{""}, delimiter{".!?"};
int pos{0};
for(int i{0}; i < str.length(); ++i) {
tmp += str[i];
pos = delimiter.find(str[i]);
if(pos > -1) {
vec.push_back(tmp);
tmp = "";
while(str[i+1] == ' ') ++i;
}
}
}
int main() {
std::string s{"Hi bro! How are you? This your string of file."};
std::vector<std::string> res;
split(s, res);
for(auto& el : res) std::cout << el << '\n';
return 0;
}
#include <iostream>
int main() {
int arr[]{1,1,1,3,4,4,2,8,7,9};
int sample[]{1,2,3,4,5,6,7,8,9,10};
int count{0}, res{0};
for(int& i : sample) {
for(int& j : arr) {
if(i == j) ++count;
}
if(count > 1) ++res;
count = 0;
}
std::cout << res;
return 0;
#include <iostream>
#include <set>
int main() {
int arr[]{1,1,1,3,4,4,2,8,7,9};
std::set<int> set;
for(int i : arr) set.insert(i);
int count{0}, res{0};
for(int el : set) {
for(int j : arr) {
if(el == j) ++count;
}
if(count > 1) ++res;
count = 0;
}
std::cout << res;
return 0;
let arr = ['9', '7', 'q', 'q', '9'];
let res = [], count = 0;
for(let i = 0; i < arr.length; ++i) {
for(let j = 0; j < arr.length; ++j) {
if(arr[i] === arr[j]) ++count;
}
if(count > 1) res.push(arr[i]);
count = 0;
}
console.log(res);
#include <stdio.h>
int main() {
int arr[10] = {-1, 0, 5, -9, 8, -3, 5, 0, -7, 4};
int tmp = 0;
for(int i = 0; i < 9; ++i) {
for(int j = 0; j < 9; ++j) {
if(arr[j] < 1) {
tmp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = tmp;
}
if(arr[j] < 0) {
tmp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = tmp;
}
}
}
for(int i = 0; i < 10; ++i) printf("%d%c", arr[i], ' ');
return 0;
}
std::vector<std::string> explode(std::string separator, std::string input) {
std::vector<std::string> vec;
for(int i{0}; i < input.length(); ++i) {
int pos = input.find(separator, i);
if(pos < 0) { vec.push_back(input.substr(i)); break; }
int count = pos - i;
vec.push_back(input.substr(i, count));
i = pos + separator.length() - 1;
}
return vec;
}