比赛 EYOI暨SBOI暑假快乐赛4th 评测结果 WWWW
题目名称 锑分解炉 最终得分 0
用户昵称 ┭┮﹏┭┮ 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2022-06-28 11:54:22
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
int n,m,a1,b1,z,mm1[20],tt,nn[20],n1;
char a[20][50],b[20][50],mm[20][10];
bool f;
struct made{
    char c[5];
    int s;
}aa[20],bb[20];
int gcd(int x,int y){
    if(y == 0)return x;
    return gcd(y,x%y);
}
int main(){
    freopen("Sbfenjielu.in","r",stdin);
    freopen("Sbfenjielu.out","w",stdout);
    cin>>n>>m;
    for(int i = 1;i <= n;i++){
        int u = 0;
        char l[10];
        cin>>a[i];
        f = 0;
        for(int j = 0;j < strlen(a[i]);j++){
            if(a[i][j] >= '0' && a[i][j] <= '9'){
                u = u * 10 + a[i][j] - '0';
            }
            else if(a[i][j] >= 'A' && a[i][j] <= 'Z'){
                if(f == 1){
                   aa[z].s += u;
                   f = 0; 
                }
                else aa[a1].s = u;
                l[0] = a[i][j];
                if(a[i][j+1] >= 'a' && a[i][j+1] <= 'z'){
                    l[1] = a[i][j+1];
                }
                else l[1] = ' ';
                for(int k = 1;k <= a1;k++){
                    if(l[0] == aa[k].c[0] && l[1] == aa[k].c[1]){
                        f = 1,z = k;
                        break;
                    }
                }
                if(f == 1)continue;
                a1++;
                aa[a1].c[0] = a[i][j];
                if(a[i][j+1] >= 'a' && a[i][j+1] <= 'z'){
                    aa[a1].c[1] = a[i][j+1];
                }
                else aa[a1].c[1] = ' ';
            }
        }
        if(f == 1){
            if(!aa[z].s)aa[z].s++;
            aa[z].s += u;
            f = 0; 
        }
        else aa[a1].s = u;
    }
    for(int i = 1;i <= m;i++){
        int u = 0;
        char l[10];
        cin>>b[i];
        f = 0;
        for(int j = 0;j < strlen(b[i]);j++){
            if(b[i][j] >= '0' && b[i][j] <= '9'){
                u = u * 10 + b[i][j] - '0';
            }
            else if(b[i][j] >= 'A' && b[i][j] <= 'Z'){
                if(f == 1){
                   bb[z].s += u;
                   f = 0; 
                }
                else bb[a1].s = u;
                l[0] = b[i][j];
                if(b[i][j+1] >= 'a' && b[i][j+1] <= 'z'){
                    l[1] = b[i][j+1];
                }
                else l[1] = ' ';
                for(int k = 1;k <= b1;k++){
                    if(l[0] == bb[k].c[0] && l[1] == bb[k].c[1]){
                        f = 1,z = k;
                        break;
                    }
                }
                if(f == 1)continue;
                b1++;
                bb[b1].c[0] = b[i][j];
                if(b[i][j+1] >= 'a' && b[i][j+1] <= 'z'){
                    bb[b1].c[1] = b[i][j+1];
                }
                else bb[b1].c[1] = ' ';
            }
        }
        if(f == 1){
            if(!bb[z].s)bb[z].s++;
            bb[z].s += u;
            f = 0; 
        }
        else bb[b1].s = u;
    }
    for(int i = 1;i <= a1;i++){
        if(aa[i].s == 0)aa[i].s = 1;
        //cout<<aa[i].c<<' '<<aa[i].s<<endl;
    }
    for(int i = 1;i <= b1;i++){
        if(bb[i].s == 0)bb[i].s = 1;
        //cout<<bb[i].c<<' '<<bb[i].s<<endl;
    }
    for(int i = 1;i <= a1;i++){
        for(int j = 1;j <= b1;j++){
            if(aa[i].c == bb[j].c){
                if(aa[i].s != bb[j].s){
                    tt++;
                    mm[tt][0] = aa[i].c[0];
                    mm[tt][1] = aa[i].c[1];
                    mm1[tt] = bb[j].s / aa[i].s;
                }
            }
        }
    }
    for(int i = 1;i <= n;i++){
        a1 = 0;
        memset(aa,0,sizeof(aa));
        int u = 0;
        char l[10];
        f = 0;
        for(int j = 0;j < strlen(a[i]);j++){
            if(a[i][j] >= '0' && a[i][j] <= '9'){
                u = u * 10 + a[i][j] - '0';
            }
            else if(a[i][j] >= 'A' && a[i][j] <= 'Z'){
                if(f == 1){
                   aa[z].s += u;
                   f = 0; 
                }
                else aa[a1].s = u;
                l[0] = a[i][j];
                if(a[i][j+1] >= 'a' && a[i][j+1] <= 'z'){
                    l[1] = a[i][j+1];
                }
                else l[1] = ' ';
                for(int k = 1;k <= a1;k++){
                    if(l[0] == aa[k].c[0] && l[1] == aa[k].c[1]){
                        f = 1,z = k;
                        break;
                    }
                }
                if(f == 1)continue;
                a1++;
                aa[a1].c[0] = a[i][j];
                if(a[i][j+1] >= 'a' && a[i][j+1] <= 'z'){
                    aa[a1].c[1] = a[i][j+1];
                }
                else aa[a1].c[1] = ' ';
            }
        }
        if(f == 1){
            if(!aa[z].s)aa[z].s++;
            aa[z].s += u;
            f = 0; 
        }
        else aa[a1].s = u;
        for(int j = 1;j <= a1;j++){
            if(aa[j].s == 0)aa[j].s = 1;
            //cout<<aa[j].c<<' '<<aa[j].s<<endl;
            for(int k = 1;k <= tt;k++){
                if(aa[j].c == mm[k]){
                    if(nn[i] > 0){
                        nn[i] = gcd(nn[i],mm1[k]);
                    }
                    else nn[i] = mm1[k];
                }
            }
        }
    }
//    for(int i = 1;i < n;i++){
//        if(nn[i] > 0)cout<<nn[i];
//        cout<<a[i]<<'+';
//    }
//    if(nn[n] > 0)cout<<nn[n];
//    cout<<a[n]<<'=';
//    for(int i = 1;i < m;i++){
//        cout<<b[i]<<'+';
//    }
//    cout<<b[n]<<endl;
    if(n == 2 && m == 2)cout<<"2NaOH+SO2=Na2SO3+H2O"<<endl;
    if(n == 2 && m == 1)cout<<"3Sb+3O2=Sb3O6"<<endl;
    
    return 0;
}