Skip to content

Instantly share code, notes, and snippets.

@mAlishera
Created March 25, 2017 22:28
Show Gist options
  • Save mAlishera/5dcae3fc7babcf85ebf74bcfb053a292 to your computer and use it in GitHub Desktop.
Save mAlishera/5dcae3fc7babcf85ebf74bcfb053a292 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <math.h>
#include <curses.h>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <time.h>
// Задача 1
// Исходн массив заполнен случайными числами
// Преобразовать его так, чтобы все нечетные элементы остались на своих местах,
// а все четные элементы расположились бы в возрастающем порядке
int main(int argc, const char * argv[]) {
const int N=30;
const unsigned short RANGE = 10;
int a[N], acc(0), tmp, var_i;
printf("\n\t" );
srand((unsigned) time(NULL));
for (int i(0); i<N; i++) {
a[i] = int (rand() %RANGE);
printf("%2d", a[i]);
}
printf("\n\t" );
for(int i=0; i<(N - 1); i++) {
for(int j=0; j<(N - 1)-i; j+=var_i) {
if (a[j]%2 != 0) {
var_i = 1;
}
if (a[j]%2 == 0) {
for(int t=1; t<(N-i-j); t++) {
if(a[j+t]%2 == 0) {
if(a[j]>a[j+t]) {
tmp = a[j]; a[j] = a[j+t];
a[j+t] = tmp;
}
var_i = t;
t = N-i-j;
}
}
}
}
}
for (int i=0; i<N; i++)
printf("%2d", a[acc++]);
}
// Задача 2
// дан массив целых чисел, который заполнен случайными, возможно повторяющимися, числами (ренж меньше длины массива),
// нужно сформировать массив, в котором нет посторений
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment