Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA用C++写的,比较水,看不出什么错,有没有测试用例啊?求大神指教

Posted by putuotingchan at 2014-08-31 23:13:35 on Problem 1007
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int inversions (string str1);

int main()
{
	int str_len = 0;
	int rows = 0;
	cin >> str_len >> rows;
	vector<string> gene;
	string s1;
	int at = 0;
	while(at < rows)
	{
		cin >> s1;
		gene.push_back(s1);
		at++;
	}

	vector<int> sort_inv(rows);
	
	for(int t2 = 0; t2 < rows; t2++)
	{
		sort_inv[t2] = inversions(gene[t2]);
		//cout << sort_inv[t2] << endl ;
	}
	

	
	
	
	//Bubble Sort
	int i,j;
	int temp;


	for(i = 0; i < rows - 1; i++ )
	{
		for(j = i + 1; j < rows; j++)
		{
			if( sort_inv[i] > sort_inv[j] )
			{
				temp = sort_inv[j];
				sort_inv[j] = sort_inv[i];
				sort_inv[i] = temp; 
			}
		}
	}//Bubble sort

	for(int i1 = 0; i1 < rows; i1++)
	{
		for(int i2 = 0; i2 < rows; i2++)
		{
			if(inversions(gene[i2]) == sort_inv[i1])
			{
				cout << gene[i2] << endl;
			}
		}
		
	}


	//system("pause");
	return 0;
}

int inversions(string str1)
{
	int invT = 0;
	int invG = 0;
	int invC = 0;
	int inv = 0;
	for (string::iterator str_iter1 = str1.begin(); str_iter1 != str1.end(); str_iter1++)
	{
		if(*str_iter1 == 'T')
		{
			for (string::iterator str_iterT = str_iter1 + 1; str_iterT != str1.end(); str_iterT++)
			{
				if((*str_iterT == 'G' ) || (*str_iterT == 'C' ) || (*str_iterT == 'A' ))
				{
					invT++;
				}
			}
		}else if(*str_iter1 == 'G')
		{
			for(string::iterator str_iterG = str_iter1 + 1; str_iterG != str1.end(); str_iterG++)
			{
				if((*str_iterG == 'C' ) || (*str_iterG == 'A' ))
				{
					invG++;
				}
			}
		}else if(*str_iter1 == 'C')
		{
			for(string::iterator str_iterC = str_iter1 + 1; str_iterC != str1.end(); str_iterC++)
			{
				if(*str_iterC == 'A' ) 
				{
					invC++;
				}
			}
		}
		inv += invT + invG + invC;
		invT = 0;
		invG = 0;
		invC = 0;
	}//for (string::iterator str_iter1; str_iter1 != str1.end(); str_iter1++)
	//cout << inv << endl;
	return inv;
}
	

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator