Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://drive.google.com/file/d/1agozx4V82KeY05FmCmyaMTWRezFYSl3M/view?usp=sharing
- //Time: 1h
- //New: ValidLetters, Consecutives, MaxRows, MaxColumns all customizable.
- #include <iostream>
- #include <string>
- #include <vector>
- enum eDirections
- {
- dHorizontal = 0,
- dVertical,
- dRightDiagonal,
- dLeftDiagonal
- };
- struct tPoints
- {
- eDirections Direction;
- char Letter;
- size_t B_R; //Begin Row
- size_t B_C; //Begin Column
- size_t E_R; //End Row
- size_t E_C; //End Column
- };
- std::vector<tPoints> AllFoundPoints;
- char NoSeqSign = '*';
- std::string ValidLetters = "ATCG";
- size_t Consecutives = 4;
- size_t MaxRows = 6;
- size_t MaxColumns = 6;
- bool IsValid(std::string Sequence)
- {
- for (size_t i = 0; i < Sequence.size(); i++)
- {
- for (size_t i2 = 0; i2 < ValidLetters.size(); i2++)
- {
- if (Sequence[i] == ValidLetters[i2])
- {
- break;
- }
- else
- {
- if (i2 == ValidLetters.size() - 1) return false;
- }
- }
- }
- return true;
- }
- void ShowFoundMatrix(std::vector<std::string> ADN)
- {
- for (size_t i = 0; i < ADN.size(); i++)
- {
- for (size_t i2 = 0; i2 < ADN[i].size(); i2++)
- {
- ADN[i][i2] = NoSeqSign;
- }
- }
- for (size_t i = 0; i < AllFoundPoints.size(); i++)
- {
- for (size_t i2 = 0; i2 < Consecutives; i2++)
- {
- switch(AllFoundPoints[i].Direction)
- {
- case eDirections::dHorizontal:
- ADN[AllFoundPoints[i].B_R][AllFoundPoints[i].B_C + i2] = AllFoundPoints[i].Letter;
- break;
- case eDirections::dVertical:
- ADN[AllFoundPoints[i].B_R + i2][AllFoundPoints[i].B_C] = AllFoundPoints[i].Letter;
- break;
- case eDirections::dRightDiagonal:
- ADN[AllFoundPoints[i].B_R + i2][AllFoundPoints[i].B_C + i2] = AllFoundPoints[i].Letter;
- break;
- case eDirections::dLeftDiagonal:
- ADN[AllFoundPoints[i].B_R + i2][AllFoundPoints[i].B_C - i2] = AllFoundPoints[i].Letter;
- break;
- }
- }
- }
- for (size_t i = 0; i < ADN.size(); i++)
- {
- for (size_t i2 = 0; i2 < ADN[i].size(); i2++)
- {
- std::cout << (!i2 ? "" : "\t\t") << ADN[i][i2] << (i2 < ADN[i].size() - 1 ? "" : "\t\t");
- }
- std::cout << std::endl;
- }
- }
- bool IsMutant(std::vector<std::string> ADN)
- {
- int Sequences = 0;
- bool AddHorizontal = false;
- bool AddVertical = false;
- bool RightDiagonal = false;
- bool LeftDiagonal = false;
- tPoints FoundPoint;
- if (ADN.size() != MaxRows)
- {
- std::cout << "ERROR de matriz: no tiene " << MaxRows << " filas." << std::endl;
- return false;
- }
- for (size_t i = 0; i < ADN.size(); i++)
- {
- if (ADN[i].size() != MaxColumns)
- {
- std::cout << "ERROR de matriz: la fila " << (i + 1) << " no tiene " << MaxColumns << " columnas." << std::endl;
- return false;
- }
- if (!IsValid(ADN[i]))
- {
- std::cout << "ERROR de secuencia: la fila " << (i + 1) << " no tiene una secuencia valida." << std::endl;
- return false;
- }
- for (size_t i2 = 0; i2 < ADN[i].size(); i2++)
- {
- FoundPoint.Letter = ADN[i][i2];
- FoundPoint.B_R = i;
- FoundPoint.B_C = i2;
- //Horizontal
- if (i2 + (Consecutives - 1) < ADN[i].size())
- {
- if (ADN[i][i2] == ADN[i][i2 + (Consecutives - 1)])
- {
- FoundPoint.E_R = i;
- FoundPoint.E_C = i2 + (Consecutives - 1);
- AddHorizontal = true;
- for (size_t i3 = 1; i3 < (Consecutives - 1); i3++)
- {
- if (ADN[i][i2] != ADN[i][i2 + i3])
- {
- AddHorizontal = false;
- break;
- }
- }
- if (AddHorizontal)
- {
- FoundPoint.Direction = eDirections::dHorizontal;
- AllFoundPoints.push_back(FoundPoint);
- std::cout << "Secuencia Horizontal encontrada desde " << FoundPoint.B_R << "," << FoundPoint.B_C << "->" << FoundPoint.E_R << "," << FoundPoint.E_C << std::endl;
- AddHorizontal = false;
- Sequences++;
- }
- }
- }
- //Vertical
- if (i + (Consecutives - 1) < ADN.size())
- {
- if (ADN[i][i2] == ADN[i + (Consecutives - 1)][i2])
- {
- FoundPoint.E_R = i + (Consecutives - 1);
- FoundPoint.E_C = i2;
- AddVertical = true;
- for (size_t i3 = 1; i3 < (Consecutives - 1); i3++)
- {
- if (ADN[i][i2] != ADN[i + i3][i2])
- {
- AddVertical = false;
- break;
- }
- }
- if (AddVertical)
- {
- FoundPoint.Direction = eDirections::dVertical;
- AllFoundPoints.push_back(FoundPoint);
- std::cout << "Secuencia Vertical encontrada desde " << FoundPoint.B_R << "," << FoundPoint.B_C << "->" << FoundPoint.E_R << "," << FoundPoint.E_C << std::endl;
- AddVertical = false;
- Sequences++;
- }
- }
- }
- //Diagonal derecha
- if (i2 + (Consecutives - 1) < ADN[i].size() && i + (Consecutives - 1) < ADN.size())
- {
- if (ADN[i][i2] == ADN[i + (Consecutives - 1)][i2 + (Consecutives - 1)])
- {
- FoundPoint.E_R = i + (Consecutives - 1);
- FoundPoint.E_C = i2 + (Consecutives - 1);
- RightDiagonal = true;
- for (size_t i3 = 1; i3 < (Consecutives - 1); i3++)
- {
- if (ADN[i][i2] != ADN[i + i3][i2 + i3])
- {
- RightDiagonal = false;
- break;
- }
- }
- if (RightDiagonal)
- {
- FoundPoint.Direction = eDirections::dRightDiagonal;
- AllFoundPoints.push_back(FoundPoint);
- std::cout << "Secuencia Diagonal Derecha encontrada desde " << FoundPoint.B_R << "," << FoundPoint.B_C << "->" << FoundPoint.E_R << "," << FoundPoint.E_C << std::endl;
- RightDiagonal = false;
- Sequences++;
- }
- }
- }
- //Diagonal izquierda
- if ((int)i2 - (Consecutives - 1) >= 0 && (int)i + (Consecutives - 1) < ADN.size())
- {
- if (ADN[i][i2] == ADN[i + (Consecutives - 1)][i2 - (Consecutives - 1)])
- {
- FoundPoint.E_R = i + (Consecutives - 1);
- FoundPoint.E_C = i2 - (Consecutives - 1);
- LeftDiagonal = true;
- for (size_t i3 = 1; i3 < (Consecutives - 1); i3++)
- {
- if (ADN[i][i2] != ADN[i + i3][i2 - i3])
- {
- LeftDiagonal = false;
- break;
- }
- }
- if (LeftDiagonal)
- {
- FoundPoint.Direction = eDirections::dLeftDiagonal;
- AllFoundPoints.push_back(FoundPoint);
- std::cout << "Secuencia Diagonal Izquierda encontrada desde " << FoundPoint.B_R << "," << FoundPoint.B_C << "->" << FoundPoint.E_R << "," << FoundPoint.E_C << std::endl;
- LeftDiagonal = false;
- Sequences++;
- }
- }
- }
- }
- }
- return (Sequences > 1);
- }
- int main()
- {
- if (Consecutives < 2)
- {
- std::cout << "Tiene que haber una mÃnima consecutividad de 2." << std::endl;
- return 0;
- }
- std::vector<std::string> Matrix;
- Matrix.push_back("ATGCGA");
- Matrix.push_back("CAGTGC");
- Matrix.push_back("TTATGT");
- Matrix.push_back("AGAAGG");
- Matrix.push_back("CCCCTA");
- Matrix.push_back("TCACTG");
- std::cout << (IsMutant(Matrix) ? "ES MUTANTE" : "NO ES MUTANTE") << std::endl;
- ShowFoundMatrix(Matrix);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement