显示代码纯文本
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
int main(void)
{
freopen("computer.in","r",stdin);
freopen("computer.out","w",stdout);
int i,j,k,len,unnum=0,num=0,temp;
double temp2;
char str[100],way,un;
bool first=true,after=false;
scanf("%s",&str);
len=strlen(str);
for (i=0;i<len;i++)
{
if (str[i]=='=')
{
first=true;
after=true;
continue;
}
if ((first&&str[i]!='-')||str[i]=='+')
{
way='+';
if (first)
i--;
first=false;
}
else// if (str[i]=='-')
{
way='-';
first=false;
}
// if (after)
// {
// if (way=='-')
// way='+';
// else
// way='-';
// }
i++;
for (j=i;j<len;j++)
if (str[j]>'9'||str[j]<'0')
break;
if (i==j)
temp=1;
else
{
temp=0;
for (k=i;k<=j-1;k++)
temp=temp*10+str[k]-'0';
}
if (way=='-')
temp=-temp;
if (after)
temp=-temp;
if (str[j]>='a'&&str[j]<='z')
{
un=str[j];
unnum+=temp;
i=j;
}
else
{
num-=temp;
i=j-1;
}
}
temp2=double(num)/double(unnum);
if (temp2>-0.001&&temp2<=0.000)
printf("%c=%.3lf\n",un,-temp2);
else
printf("%c=%.3lf\n",un,temp2);
fclose(stdin);
fclose(stdout);
return(0);
}