Vector I
Vector I
Vector I
h>
using namespace std;
ifstream fi("haha.in");
ofstream fo("haha.out");
int scan(int v[1001], int n) {
for (int i = 1; i <= n; i++)
fi >> v[i];
}
int print_console(int v[1001], int n) {
for (int i = 1; i <= n; i++)
cout << v[i] << ' ';
cout << '\n';
}
int print_file(int v[1001], int n) {
for (int i = 1; i <= n; i++)
fo << v[i] << ' ';
fo << '\n';
}
int minim(int v[1001], int n) {
int mini = 2e9;
for (int i = 1; i <= n; i++)
mini = min(v[i], mini);
return mini;
}
int maxim(int v[1001], int n) {
int maxi = -2e9;
for (int i = 1; i <= n; i++)
maxi = max(v[i], maxi);
return maxi;
}
int sum_arr(int v[1001], int n) {
int sum = 0;
for (int i = 1; i <= n; i++)
sum += v[i];
return sum;
}
int prod_arr(int v[1001], int n) {
long long prod = 1;
for (int i = 1; i <= n; i++)
prod *= v[i];
return prod;
}
int fr_even(int v[1001], int n) {
int even = 0;
for (int i = 1; i <= n; i++)
even += !(v[i]%2);
return even;
}
int search_uns(int v[1001], int n, int x) {
for (int i = 1; i <= n; i++)
if (v[i] == x) return i;
return 0;
}
int bin_s(int v[1001], int x, int st, int dr) {
if (st > dr) return 0;
int mid = (st+dr)/2;
if (v[mid] == x) return mid;
if (v[mid] < x) return bin_s(v, x, mid, dr);
if (v[mid] > x) return bin_s(v, x, st, mid);
}
bool is_full_pr(int v[1001], int n) {
for (int i = 1; i <= n; i++) {
if (v[i] == 0) return 0;
if (v[i] == 1) return 0;
for (int j = 2; j <= sqrt(v[i])+1; j++)
if (!(v[i]%j)) return 0;
}
return 1;
}
bool has_pr(int v[1001], int n) {
for (int i = 1; i <= n; i++) {
bool is_pr = 1;
if (v[i] == 0 || v[i] == 1) is_pr = 0;
for (int j = 2; j <= sqrt(v[i])+1; j++)
if (!(v[i]%j)) is_pr = 0;
if (is_pr) return 1;
}
return 0;
}
bool has_at_least_1_pr(int v[1001], int n) {
return has_pr(v, n);
}
void swap_arr(int v[1001], int n) {
for (int i = 1; i <= n/2; i++)
swap(v[i], v[n-i+1]);
}
void add_x_on_k(int v[1001], int &n, int x, int k) {
for (int i = n; i >= k; i--)
v[i+1] = v[i];
v[k] = x;
n++;
}
void del_on_k(int v[1001], int &n, int k) {
for (int i = k; i <= n; i++)
v[i] = v[i+1];
n--;
}
void select_mini_sort(int v[1001], int n) {
for (int i = 1; i < n; i++) {
int mini = 2e9, poz = i;
for (int j = i+1; j <= n; j++)
if (v[j] < mini) {
mini = v[j];
poz = j;
}
swap(v[i], v[poz]);
}
}
void bub_sort(int v[1001], int n) {
bool ok=0;
while (!ok)
{
ok=1;
for (int i = 1; i < n; i++)
if (v[i] > v[i+1])
{
swap(v[i],v[i+1]);
ok=0;
}
}
}
void count_sort(int v[1001], int n) {
int w[1001], y[1001];
for (int i = 1; i <= 1000; i++) w[i] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
if (v[i] > v[j]) w[i]++;
}
for (int i = 1; i <= n; i++)
y[w[i]+1] = v[i];
for (int i = 1; i <= n; i++) v[i] = y[i];
}
void intercls(int a[1001], int n_a, int b[1001], int n_b, int c[2001]) {
int i = 1, j = 1, k = 0;
while (i <= n_a && j <= n_b) {
if (a[i] < b[j]) c[++k] = a[i++];
else c[++k] = b[j++];
}
if (i > n_a)
for (; j <= n_b; j++) c[++k] = b[j];
else
for (; i <= n_a; i++) c[++k] = b[i];
}