The given code takes an input n which represents the number of genes. It then takes n integers as input which represents the genes.

The function isAlienGene takes an integer gene as input and checks if the square of the gene modulo 7 is equal to 1. If it is, the function returns true, indicating that the gene is an alien gene. Otherwise, it returns false.

The function removeAlienGenes takes a vector of genes as input and creates a new vector result. It iterates through the genes and checks if each gene is an alien gene using the isAlienGene function. If a gene is not an alien gene, it adds it to the result vector. Finally, it returns the result vector.

In the main function, it first takes the input n and creates a vector genes of size n. It then takes n integers as input and stores them in the genes vector. It calls the removeAlienGenes function to remove alien genes from the genes vector and stores the result in a new vector normalGenes. It then prints the elements of the normalGenes vector.

Overall, the code removes alien genes from a given list of genes and prints the remaining normal genes

#include iostream#include vectorusing namespace std;bool isAlienGeneint gene int remainder = gene gene 7; return remainder == 1;vectorint removeAlienGenesvectorint& genes vectorint result

原文地址: http://www.cveoy.top/t/topic/hXHG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录