Created
May 15, 2011 20:06
-
-
Save pony012/973485 to your computer and use it in GitHub Desktop.
genetica
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 <iostream> | |
using namespace std; | |
bool isprime(int n); | |
int main(){ | |
int n,i,j; | |
cin>>n; | |
fflush(stdin); | |
char cpadre[n],cmadre[n],temp; | |
short int padre[n],madre[n],hijo[n]; | |
cin.getline(cpadre,n+1); | |
fflush(stdin); | |
cin.getline(cmadre,n+1); | |
fflush(stdin); | |
for(i=0;i<n;i++){ | |
temp=cpadre[i]; | |
padre[i]=atoi(&temp); | |
temp=cmadre[i]; | |
madre[i]=atoi(&temp); | |
} | |
for(i=0; i<n; i+=4){ | |
hijo[i]=isprime(padre[i]+padre[i+2])?padre[i]:padre[i+2]; | |
hijo[i+1]=isprime(madre[i]+madre[i+2])?madre[i]:madre[i+2]; | |
hijo[i+2]=isprime(padre[i+1]+padre[i+3])?padre[i+1]:padre[i+3]; | |
hijo[i+3]=isprime(madre[i+1]+madre[i+3])?madre[i+1]:madre[i+3]; | |
} | |
for(i=0; i<n; i++) | |
cout<<hijo[i]; | |
} | |
bool isprime(int n){ | |
int i=2; | |
for(i; i<n; i++) | |
if(n%i==0) return 0; | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment