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啊#include <iostream> #include <cstdlib> #include <vector> #include <cstring> #include <cmath> #include <string> using namespace std; void ltoi( string &str ,int &x,int &num); int numlen( char *cstr ); const double LIMIT=0.000001; int main(){ int a = 0; int line; cin >> line; while( a < line && line <=10 && line >= 1 ){ int n; int len; string str; double ans = 0; vector<int> num; vector<int> x; int num_t = 0 ,x_t = 0; getline( cin ,str ); while( str[ 0 ] != '=' ){ int x1 = 0 ,num1 = 0; ltoi(str,x1,num1); if( x1 ) x.push_back(-x1); if( num1 ) num.push_back(-num1); if( str[ 0 ] =='+' ) str =str.substr(1); } str = str.substr(1); while( str[ 0 ] ){ int x1 = 0 ,num1 = 0; ltoi(str,x1,num1); if( x1 ) x.push_back(x1); if( num1 ) num.push_back(num1); if( str[ 0 ] =='+' ) str =str.substr(1); } for( int i = 0 ;i < x.size(); i++ ) x_t += x[ i ]; for( int i = 0 ;i < num.size(); i++ ) num_t += num[ i ]; if( x_t == 0 ){ if( num_t== 0 ) cout << "IDENTITY"; else cout << "IMPOSSIBLE"; } else{ ans = -num_t/x_t; if(fabs(ans)<LIMIT) cout << 0; else cout << floor(ans); } cout << endl; } return 0; } void ltoi( string &str ,int &x,int &num){ int n,len; char str1[255]; if( str[ 0 ] == 'x' ){ n = 1; str = str.substr(1); x = 1; } else if( str[ 0 ] == '-' && str[ 1 ] == 'x' ){ n = -1; str = str.substr(2); x = -1; } else{ n = atoi(str.c_str()); sprintf(str1,"%d",n); len = numlen(str1); if( str[ len ] == 'x' ){ x = n; str = str.substr(len+1); } else{ num = n; str = str.substr(len); } } } int numlen( char *cstr ){ int i; for( i = 0 ;cstr[ i ] ; i++ ); return i; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator