Bioinformatics: find genes)

PHOTO EMBED

Wed Jan 20 2021 22:02:30 GMT+0000 (Coordinated Universal Time)

Saved by @mahmoud hussein #c++

#include <iostream>

#include <string>
using namespace std;
#define ll long long



int intOfEnd(string& s)
{
	int start = s.find("ATG");
	int end1 = s.find("TAG", start);
	int end2 = s.find("TAA", start);
	int end3 = s.find("TGA", start);

	int list[3] = { end1,end2,end3 };
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (list[i] < list[j] && list[i] != string::npos)
				return list[i];
		}
	}
	
	for (int i = 0; i < 3; i++)
	{
		if (list[i] != string::npos)
			return list[i];
	}
	return 0;
	

}
int main()
{
	string s;
	cin >> s;
	
	
	string ans("");
	int l = 0;
	
	for (int j = 0; j < s.length(); j++)
	{
			int start = s.find("ATG");
			if ((start != string::npos && intOfEnd(s) != 0))
			{
				for (int i = start + 3; i < intOfEnd(s); i++)
				{
					ans += s[i];
				}
				cout << "gene "<<ans << endl;

				s.erase(start, 6);
				ans.clear();
				l++;
			}
			
	}
	if (l == 0)
		cout << "no gene found ";
}




content_copyCOPY

http://cpp.sh/