Ecuación química

Descripción del título

La clase 102 escribe ecuaciones químicas todos los días, ahora tenemos que encontrar formas de corregir las ecuaciones. El orden de los reactivos en la ecuación puede ser diferente, con espacios intermedios. No habrá signos de precipitación y gas y condiciones de reacción. Hay coeficientes incorrectos (cuando el subíndice es incorrecto, si el CO2 es CO3, el coeficiente también es incorrecto. Las fórmulas químicas con el mismo elemento y coeficientes diferentes no aparecerán en el reactivo o producto, tales como: CO y CO2 no aparecerán juntos en el reactivo o producto Medio), fórmula química incorrecta, falta de reactivos, elementos en ambos lados no se conservan.

De entrada

Ingrese N, M en la primera fila

Ingrese una cadena de longitud N en la segunda fila como la ecuación correcta

Introduzca una cadena de longitud M en la tercera fila para corregir la ecuación

Salida

Salida correcta DERECHA

Los errores INCORRECTOS se muestran en la primera fila, y la causa del error se muestra en la segunda fila (solo el coeficiente es incorrecto es 1, otros errores y más de dos errores son 2)

Entrada de muestra

34 29 
2Na OH + H2S O4 = Na 2 S O4 + 2H2O 
H2S O4 + 2NaO H = Na2 S O4 + 2H2O

Salida de muestra

CORRECTO

Pronto

34 25

2Na OH + H2S O4 = Na2SO4 + 2H2O

H2S O4
+ NaO H = 2H2O +2 K Cl

INCORRECTO

2

1 <= N <= 100

1 <= M <= 100

Código

#pragma GCC optimice (1)
 #pragma GCC optimice (2)
 #pragma GCC optimice (3)
 #pragma GCC optimice ("Ofast") 
#include <bits / stdc ++. h>
 #define rep (i, j, k) para (registre int i = (j); i <= (k); i ++)
 usando el  espacio de nombres estándar;
char a [ 1005 ], b [ 1005 ]; 
vector < cadena > ys1, ys2;
int fff, h1, h2; 
plantilla < clase T> inline void read (T & x) { 
    x = 0 ; 
    Registrarsechar c = getchar (); 
    registrar bool f = 0 ;
    mientras que (! isdigit (c)) f ^ = c == ' - ' , c = getchar ();
    while (isdigit (c)) x = x * 10 + c - ' 0 ' , c = getchar ();
    si (f) x = - x; 
} 
string getnum ( cadena s) 
{ 
    string tmp = "" ;
    int len = s.length ();
    para ( int i = 0; i <len; i ++ ) 
    { 
        if (s [i] <= ' 9 ' && s [i]> = ' 0 ' ) 
        { 
            tmp = tmp + s [i]; 
        } 
    } 
    return tmp; 
} 
string getchar ( string s) 
{ 
    string tmp = "" ;
    int len = s.length ();
    para ( int i = 0 ; i <len; i ++ ) 
    { 
        if (s [i]> ' 9 ' || s [i] < '0 ' ) 
        { 
            tmp = tmp + s [i]; 
        } 
    } 
    return tmp; 
} 
bool check ( char x) 
{ 
    if (x <= ' 9 ' && x> = ' 0 ' ) devuelve  verdadero ;
    if (x <= ' Z ' && x> = ' A ' ) devuelve  verdadero ;
    if (x <= ' z ' && x> = ') devuelve  verdadero ;
    if (x == '  ' || x == ' + ' || x == ' = ' ) devuelve  verdadero ;
    devuelve  falso ; 
} 
int main () 
{ 
    string tmp = "" ; 
    obtiene (a); 
    obtiene (a); 
    obtiene (b); 
    int n = strlen (a);
    int m = strlen (b);
    for ( int i = 0 ; i <n; i ++ ) 
    { 
        if(fff == 0 && a [i]! = '  ' ) h1 + = a [i];
        if (a [i] == ' = ' ) fff = 1 ;
        if (marque (a [i])! = 1 ) continuar ;
        if (a [i] == ' + ' || a [i] == ' = ' ) 
        { 
            ys1.push_back (tmp); 
            tmp = "" ; 
        } 
        else  if (a [i]! = '  ' ) 
        { 
            tmp = tmp +ai]; 
        } 
    } 
    if (tmp! = "" ) 
    { 
        ys1.push_back (tmp); 
    } 
    tmp = "" ; 
    fff = 0 ;
    para ( int i = 0 ; i <m; i ++ ) 
    { 
        if (fff == 0 && b [i]! = '  ' ) h2 + = b [i];
        if (b [i] == ' = ' ) fff = 1 ;
        if (marcar (b [i])! = 1 ) continuar ;
        if (b [i] == ' + ' || b [i] == ' = ' ) 
        { 
            ys2.push_back (tmp); 
            tmp = "" ; 
        } 
        else  if (b [i]! = '  ' ) 
        { 
            tmp = tmp + b [i]; 
        } 
    } 
    if (tmp! = "" ) 
    { 
        ys2.push_back (tmp); 
        tmp = "" ; 
    } 
    sort (ys1.begin (), ys1.end ()); 
    sort (ys2.begin (), ys2.end ()); 
    Si(ys1 == ys2) 
    { 
        if (h1 == h2) 
        { 
            cout << " DERECHA " << endl;
            devuelve  0 ; 
        } 
    } 
    int c1 = 0 , c2 = 0 ;
    if (ys1.size ()! = ys2.size ()) 
        c1 = 1 , c2 = 1 ;
    else 
    { 
        n = ys1.size ();
        para ( int i = 0 ; i <n; i ++ ) 
        {
            if (ys1 [i]! = ys2 [i]) 
            { 
                if (getnum (ys1 [i])! = getnum (ys2 [i])) 
                    c1 = 1 ;
                if (getchar (ys1 [i])! = getchar (ys2 [i])) 
                    c2 = 1 ; 
            } 
        } 
    } 
    cout << " INCORRECTO " << endl;
    if (c1 == 1 && c2 == 0 ) cout << 1 << endl;
    sino cout << 2 << endl;
    regreso 0 ; 
}

Supongo que te gusta

Origin www.cnblogs.com/LJA001162/p/12678601.html
Recomendado
Clasificación