Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:在vs2008上测试所有数据没有问题,提交后却编译失败,刚刚接触C++,麻烦大家看一下,谢谢In Reply To:在vs2008上测试所有数据没有问题,提交后却编译失败,刚刚接触C++,麻烦大家看一下,谢谢 Posted by:deking at 2008-05-01 02:15:29 > 刚刚想写一个super_figure的类,写了一大部分发现,可以直接过了这道题目,在本地所有的测试都能过 > > 提交竟然编译失败,麻烦大家帮我看看; #include <iostream> #include <string> using namespace std; > class super_figure > { > public: > super_figure(string s = "0"); > super_figure(super_figure &s); > super_figure operator=(string s); > super_figure operator=(super_figure&s); > super_figure& operator*=( super_figure &s); > super_figure& operator/=(super_figure &s); > super_figure& operator+=(super_figure &s); > super_figure& operator-=(super_figure &s); > friend super_figure operator*(super_figure &s1, super_figure&s2); > friend super_figure operator/(super_figure &s1, super_figure&s2); > friend super_figure operator+(super_figure &s1, super_figure&s2); > friend super_figure operator-(super_figure &s1, super_figure&s2); > friend super_figure Evolution(super_figure&s, int k); > friend ostream& operator<<(ostream&os, super_figure &figure); > friend istream& operator>>(istream &os, super_figure &figure); > friend super_figure Logarithm(super_figure &figure1, super_figure& figure2); > bool Compare(super_figure &data); > private: > string data; > char symbol; > int position; > }; 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator