爱问知识人 爱问教育 医院库

百度知道 理工学科 添加到搜藏 待解决 帮忙看下这道题为什么RE

首页

百度知道 理工学科 添加到搜藏 待解决 帮忙看下这道题为什么RE

百度知道 > 理工学科 添加到搜藏 待解决 帮忙看下这道题为什么RE百度知道 > 理工学科 添加到搜藏 待解决 帮忙看下这道题为什么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;
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 = bstr(1);
}
str =  bstr(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 = bstr(1);
}
for( int i = 0 ;i <  ze(); i++ )
x_t += x[ i ];
for( int i = 0 ;i <  ze(); 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 if(ans > 0)
cout << floor(ans);
else if(ans < 0)
cout << floor(ans)-1;
}
cout << endl;
}
return 0;
}

void ltoi( string &str ,int &x,int &num){
int n,len;
char str1[260];
if( str[ 0 ] == 'x' ){
n = 1;
str =  bstr(1);
x = 1;
}
else if( str[ 0 ] == '-' && str[ 1 ] == 'x' ){
n = -1;
str =  bstr(2);
x = -1;
}
else{
n = atoi(str.c_str());
sprintf(str1,"%d",n);
len = numlen(str1);
if( str[ len ] == 'x' ){
x = n;
str =  bstr(len+1);
}
else{
num = n;
str =  bstr(len);
}
}
}

int numlen( char *cstr ){
int i;
for( i = 0 ;cstr[ i ] ; i++ );
return i;
}

提交回答

全部答案

  • C/C++ 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 178-197
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):