Created
September 16, 2017 15:00
-
-
Save invatainfo/0e5664ff71756d83ac44b1db1542bc9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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