求解哪错!?
查看原帖
求解哪错!?
187
qqqq楼主2013/7/2 09:21
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
float x=1.0;char q;int z;
struct qq{int a,b;};
qq f1,f2;
string s,s1,s2;
int eat1(string t)
{   int x=0;
    for(int i=0;i<t.size();i++)x=10*x+(t[i]-'0');
    return x;   }
qq eat2(string w)    
{  qq g; 
   int i=0,a=0,b=0;
   while(i<w.size())
   {int c=1,j=i,o=1;string t;
    if(w[i]=='+'){o=1;i++;j=i;}if(w[i]=='-'){o=-1;i++;j++;}
    while((w[j]<='9')&&(w[j]>='0'))j++;if(j>i){t=w.substr(i,j-i);c=eat1(t);i=j;}
    c=c*o;if(w[j]==q){a=a+c;i++;}else b=b+c;}
    g.a=a;g.b=b;return g;}
int main()
{ cin>>s;
  z=s.find('=');
  for(int i=0;i<s.size();i++)if('9'<s[i]){q=s[i];break;}
  s1=s.substr(0,z);
  s2=s.substr(z+1,s.size());
  f1=eat2(s1);f2=eat2(s2);
  f1.a=f1.a-f2.a;f2.b=f2.b-f1.b;    
  x=(f2.b*1.0)/f1.a;
  cout<<q<<'=';printf("%0.3f",x);
  system("pause");
return 0;
}
2013/7/2 09:21
加载中...