Skip to content

Instantly share code, notes, and snippets.

@invatainfo
Created September 16, 2017 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invatainfo/0e5664ff71756d83ac44b1db1542bc9d to your computer and use it in GitHub Desktop.
Save invatainfo/0e5664ff71756d83ac44b1db1542bc9d to your computer and use it in GitHub Desktop.
#include <fstream.h>
ofstream f("bac.txt");
void main() {
int n, v[300], i, p = 0, ip = 0, gasit;
cin >> n;
for (i = 1; i <= n * 3; i++)
cin >> v[i];
gasit = 0;
i = 1;
while (i <= n && !gasit) {
if (v[i] % 2 == 0) {
gasit = 1;
p = i;
}
i++;
}
gasit = 0;
i = 3 * n;
while (i >= 2 * n + 1 && !gasit) {
if (v[i] % 2 == 1) {
gasit = 1;
ip = i;
}
i--;
}
if (p != 0 && ip != 0) {
int aux = v[p];
v[p] = v[ip];
v[ip] = aux;
}
for (i = 1; i <= n * 3; i++)
f << v[i] << " ";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment