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

为什么用C++编译能通过G++就Compile Error呢?我在本机测试的时候也是用的g++啊

Posted by ttklboy at 2011-11-09 15:04:39 on Problem 1007
#include <string>
#include <iostream>
#include <set>
#include <memory.h>

class DNAString
{
public:
	void calculate();
private:
	std::string seq;
	int measure;
	friend bool operator<(const DNAString& left, const DNAString& right);
	friend std::istream& operator>>(std::istream& is, DNAString&);
	friend std::ostream& operator<<(std::ostream& os,const DNAString&);

};

std::istream& operator>>(std::istream& is, DNAString& s)
{
	is>>s.seq;
	s.calculate();
	return is;
}

std::ostream& operator<<(std::ostream& os, const DNAString& s)
{
	os<<s.seq;
	return os;
}

bool operator<(const DNAString& left, const DNAString& right)
{
	return left.measure < right.measure;
}

void DNAString::calculate()
{
	measure=0;
	const int length = seq.length();
	char* p=new char[length];
	memcpy(p, seq.c_str(), length );
	for(int i=length-2; i>=0; --i){
		int k=i;
		for(int j=i+1; j<length;j++){
			if(p[k] > p[j]){
				std::swap(p[k], p[j]);
				measure++;
				k=j;
			}
		}
	}
	delete p;
}


int main()
{
	int m,n;
	DNAString tmp;
	std::multiset<DNAString> s;
	typedef std::multiset<DNAString>::iterator Iter;

	std::cin>>m>>n;
	for(int i=0; i< n; ++i){
		std::cin>>tmp;
		s.insert(tmp);
	}
	for(Iter iter=s.begin(); iter!= s.end(); ++iter){
		std::cout<<(*iter) <<std::endl;
	}
	return 0;
}

	

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