记录编号 |
166184 |
评测结果 |
AAAAA |
题目名称 |
[NOIP 2000PJ]计算器的改良 |
最终得分 |
100 |
用户昵称 |
<蒟蒻>我要喝豆奶 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.001 s |
提交时间 |
2015-06-14 15:04:57 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
queue<int> unpos;//未知数位置
queue<int> coe;//未知数系数
queue<int> con;//常数项
queue<int> copos;//常数位置
int pos;
string s;
char x;
int main()
{
freopen("computer.in","r",stdin);
freopen("computer.out","w",stdout);
cin>>s;
s=' '+s+' ';
for(int i=1;i<=s.size()-1;i++)
{
if(s[i]=='=')
pos=i;
if(s[i]>=97)
{
x=s[i];
unpos.push(i);
int temp=i;
int ch=0;
while(1)
{
if(s[temp-1]==' '||s[temp-1]=='-'||s[temp-1]=='+'||s[temp-1]=='=')
break;
ch++;
temp--;
}
if(ch==0)
coe.push(1);
else
{
string s2=s.substr(temp,ch);
int data=0;
for(int j=0;j<=s2.size()-1;j++)
data+=pow(10,s2.size()-j-1)*(s2[j]-48);
if(s[temp-1]=='-')
coe.push(-1*data);
else
coe.push(data);
}
}
if(s[i]>=48&&s[i]<=57&&(s[i+1]=='-'||s[i+1]=='+'||s[i+1]=='='||s[i+1]==' '))
{
copos.push(i);
int temp=i;
int ch=1;
while(1)
{
if(s[temp-1]==' '||s[temp-1]=='-'||s[temp-1]=='+'||s[temp-1]=='=')
break;
ch++;
temp--;
}
string s2=s.substr(temp,ch);
int data=0;
for(int j=0;j<=s2.size()-1;j++)
data+=pow(10,s2.size()-j-1)*(s2[j]-48);
if(s[temp-1]=='-')
con.push(-1*data);
else
con.push(data);
}
}
int left=0;
int right=0;
while(!unpos.empty())
{
int unposs=unpos.front();
int coee=coe.front();
// cout<<"unposs "<<unposs<<"coee "<<coee<<endl;
if(unposs>pos)
right+=-1*coee;
else
right+=coee;
unpos.pop();
coe.pop();
}
while(!copos.empty())
{
int coposs=copos.front();
int conn=con.front();
//cout<<"coposs "<<coposs<<"conn "<<conn<<endl;
if(coposs>pos)
left+=conn;
else
left+=-1*conn;
copos.pop();
con.pop();
}
//cout<<right<<" "<<left<<endl;
double zuo=right;
double you=left;
cout<<x<<"=";
printf("%.3f",you/zuo);
// system("pause");
return 0;
}