Skip to content

Instantly share code, notes, and snippets.

@invatainfo
Created June 28, 2018 17:03
Show Gist options
  • Save invatainfo/932a92f999c1ea09190eb25cfeaee9c7 to your computer and use it in GitHub Desktop.
Save invatainfo/932a92f999c1ea09190eb25cfeaee9c7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string.h>
using namespace std;
int main() {
char s[101],c[101];
cin.get(s,100);
cin.get();
cin.get(c,100);
int n;
if ((n = strlen(c)) != strlen(s)) {
cout << "cod incorect\n";
return 0;
}
int i, pozPare = 0, pozImpare = n - 1; // variabilele poz folosite
// pentru a sti unde adaug litera
// daca in cod am cifra para sau nu
char permutare[101];
for (i = n - 1; i > 0; i--) {
if ((c[i] - '0') % 2 == 0)
permutare[pozPare++] = s[i];
else
permutare[pozImpare--] = s[i];
}
permutare[pozPare] = s[0];
permutare[n] = '\0';
cout << permutare << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment