模拟赛20181015 模拟

#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i=x;i<=y;i++)
using namespace std;

typedef map<string,int>::iterator it;
map<string,int> mp,bf;
string s,t;int n;

void make(string s,int cnt,int ty){ int now=0;
while(now<s.size()){
if(s[now]=='('){
int tmp2=now,tot=1;
while(tot){
if(s[++tmp2]=='(') tot++;
else if(s[tmp2]==')') tot--;}

int tmp3=tmp2+1,num=0;
while(tmp3<s.size()&&isdigit(s[tmp3]))
num=num*10+s[tmp3]-'0',tmp3++;
num=max(num,1);
make(s.substr(now+1,tmp2-now-1),num*cnt,ty);
now=tmp3;
}else{
int tmp4=now,num=0;
while(islower(s[++tmp4]));
string sx=s.substr(now,tmp4-now);now=tmp4;
while(isdigit(s[now])) num=num*10+s[now]-'0',now++;
mp[sx]+=max(num,1)*cnt*ty;
}
}
}
/*
统计答案的步骤
1.将串的长度确定的找出来
将后缀的数字/前缀的数字确认的算出来
保证答案不为0
进行递归统计
*/
int main(){
freopen("chem.in","r",stdin);
freopen("chem.out","w",stdout);

cin>>s;int now=0;
while(now<s.size()){
int tmp=now,cnt=0;
while(++tmp<s.size()&&s[tmp]!='+');//++顺序不同
while(isdigit(s[now])) cnt=cnt*10+s[now]-'0',now++;//前缀数字
cnt=max(cnt,1);//保持答案不为0
make(s.substr(now,tmp-now),cnt,1);now=tmp+1;
}
bf=mp;t=s;cin>>n;
rep(i,1,n){ mp=bf;bool FG=1;
cin>>s;int now=0;

while(now<s.size()){
int tmp=now,cnt=0;
while(++tmp<s.size()&&s[tmp]!='+');
while(isdigit(s[now])) cnt=cnt*10+s[now]-'0',now++;
cnt=max(cnt,1);
make(s.substr(now,tmp-now),cnt,-1);now=tmp+1;
}

for(it i=mp.begin();i!=mp.end();i++)
if(i->second!=0){cout<<t<<"!="<<s<<endl;FG=0;break;}

if(FG) cout<<t<<"=="<<s<<endl;}
return 0;} 

C2H5OH+3O2+3(SiO2)
7
2CO2+3H2O+3SiO2
2C+6H+13O+3Si
99C2H5O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P+Q+R+S+T+U+V+W+X+Y+Z
ABCDEFGH+IJKLMONPQ+RSTUVWXYZ==ABC+MONPQRS+TUVWXYZD+EFGHIJKL
ABCDEFGH+IJKLMONPQ+RSTUVWXYZ==((B(E(F)(G)(H)(I)(J)K(((((((((((((((((LM((O))N)))))))))))))))))PQ(R)S(T)U)VWX)YZ)((((A))))+(((CD)))
ABCDEFGH+IJKLMONPQ+RSTUVWXYZ!=((AB(E(F)(G)(H)(I)(J)K(((((((((((((((((LM((O))N)))))))))))))))))PQ(R)S(T)U)VWX)YZ)((((A))))+(((CD)))
ABCDEFGH+IJKLMONPQ+RSTUVWXYZ!=((B(E(F)(G)(H)(I)(J)K(((((((((((((((((LM((O))N)))))))))))))))))PQ(R)S(T)U)VWX)YZ)((((Ai))))+(((CD)))

posted @ 2018-10-18 18:22  ASDIC减除  阅读(120)  评论(0编辑  收藏  举报