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

Re:在vs2008上测试所有数据没有问题,提交后却编译失败,刚刚接触C++,麻烦大家看一下,谢谢

Posted by chinimei at 2008-07-13 16:13:11 on Problem 1001
In Reply To:Re:在vs2008上测试所有数据没有问题,提交后却编译失败,刚刚接触C++,麻烦大家看一下,谢谢 Posted by:deking at 2008-05-01 02:45:02
> #include <iostream>
> #include <string>
> using namespace std;
> super_figure super_figure::operator =(string s)
> {
> 	*this = super_figure(s);
> 	return *this;
> }
> super_figure super_figure::operator =(super_figure &s)
> {
> 	data = s.data;
> 	symbol = s.symbol;
> 	position = s.position;
> 	return *this;
> }
> super_figure::super_figure( string s)
> {
> 	int start, i, flag = 0;
> 	if(s.at(0) != '-'){
> 		symbol = '+';
> 		start = 0;
> 	}
> 	else{
> 		symbol = '-';
> 		start = 1;
> 	}
> 	data = "";
> 	for (i = start; i < s.size(); i++)
> 	{
> 		if(s.at(i) == '.'){
> 			position = i - start;
> 			i++;
> 			flag = 1;
> 		}
> 		data.push_back(s.at(i));
> 	}
> 	if(!flag){
> 		position = s.size();
> 	}
> }
> 
> super_figure::super_figure(super_figure &s)
> {
> 	data = s.data;
> 	symbol = s.symbol;
> 	position = s.position;
> }
> super_figure operator*(super_figure &s1, super_figure& s2)
> {
> 	super_figure buff;
> 	string buff1 ="", buff2 ="", buff3 = "";
> 	char  temporary = '0', temp[10000];
> 	memset( temp, '0', 10000 * sizeof( char ) );
> 	long increase, i, j, flag = 0, add, now, lenth;
> 	buff.data = "";
> 	if(s1.symbol == s2.symbol)
> 		buff.symbol = '+';
> 	else
> 		buff.symbol = '-';
> 	increase = ( s1.data.size() - s1.position ) + ( s2.data.size() - s2.position);
> 	for(i = 0; i < s1.data.size(); i++){
> 		if(!flag && s1.data.at(i) != '0')
> 			flag = 1;
> 		if(flag)
> 			buff1.push_back(s1.data.at(i));
> 	}
> 	flag = 0;
> 	for(i = 0; i < s2.data.size(); i++){
> 		if(!flag && s2.data.at(i) != '0')
> 			flag = 1;
> 		if(flag)
> 			buff2.push_back(s2.data.at(i));
> 	}
> 	for( i = buff1.size() - 1; i >= 0; i--)
> 		buff3.push_back(buff1.at(i));
> 	buff1 = buff3;
> 	buff3 = "";
> 	for(i = buff2.size() - 1; i >= 0; i--)
> 		buff3.push_back(buff2.at(i));
> 	buff2 = buff3;
> 	buff3 = "";
> 	add = 0;
> 	for(i = 0; i < buff1.size(); i++){
> 		for (j = 0; j < buff2.size(); j++)
> 		{
> 			now = ( buff1.at(i) - '0' ) * (buff2.at(j) - '0') + add + temp[i+j] -'0';
> 			add = now / 10;
> 			now %= 10;
> 			temp[i+j] = now + '0';
> 		}
> 		temp[i+j] = temp[i+j] + add;
> 		if( j != buff2.size() || i != buff1.size() - 1 )
> 			add = 0;
> 	}
> 	if(add == 0)
> 		lenth = i + j - 1;
> 	else 
> 		lenth = i + j;
> 	if(increase >= lenth)
> 		lenth = lenth + (increase - lenth ) + 1;
> 	else
> 		buff.position = lenth - increase ;
> 	i = lenth - 1;
> 	while (i >= 0){
> 		buff.data.push_back(temp[i]);
> 		i--;
> 	}
> 	return buff;
> }
> super_figure& super_figure::operator*=(super_figure& s)
> {
> 	*this = super_figure(*this) * s;
> 	return *this;
> }
> super_figure Evolution(super_figure&s, int k)
> {
> 	super_figure buff("1");
> 	while( k--){
> 		buff *= s;
> 	}
> 	return buff;
> }
> ostream& operator<<(ostream&os, super_figure&figure)
> {
> 	int i;
> 	if(figure.symbol == '-')
> 		os << "-";
> 	if(figure.data.size() == figure.position)
> 		os << figure.data;
> 	else
> 	{
> 		int flag = 0, i, j, k;
> 		for( j = figure.data.size() - 1; j >= figure.position; j--){
> 			if( figure.data.at(j) != '0')
> 				break;
> 		}
> 		if(j ==  figure.position - 1){
> 			for(i = 0; i < figure.position; i++)
> 				os << figure.data.at(i);
> 		}
> 		else{
> 			if(figure.data.at(0) != '0')
> 			{
> 				for( i = 0; i <= figure.position; i++)
> 					os <<figure.data.at(i);
> 			}
> 			os << ".";
> 			for( i = figure.position; i <= j; i++ )
> 				os << figure.data.at(i);
> 		}
> 		os << endl;
> 		return os;
> 	}
> }
> istream& operator>>(istream &os, super_figure& figure)
> {
> 	string buff;
> 	os >> buff;
> 	figure = buff;
> 	return os;
> }
> int main()
> {
> 	super_figure s, j;
> 	int k;
> 	while(cin >> s >> k)
> 	{
> 		j = Evolution(s, k);
> 		cout << j << 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