L - Chemistry Class


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Chemistry

Amin hates his chemistry class. Niloufar, who has not finished her chemistry assignments yet, turns to Amin for help with balancing chemical reactions.

Balancing a reaction means adding coefficients in front of the reactants and products so that the number of each element on both sides of the reaction is equal.

Amin has no idea what chemistry is, but he knows that chemical element names start with an uppercase letter, followed by lowercase letters.

Help Amin to check whether the reaction is balanced or not. Note that the coefficients must be integers and should be in their simplest form.

ورودی🔗

The first line of input contains a positive integer tt, representing the number of chemical reactions.

1t1001 \leq t \leq 100

In the next tt lines, each line contains a chemical reaction.

1s1001 \leq |s| \leq 100

It is guaranteed that the coefficients are less than 100100.

خروجی🔗

For each test, if the reaction is balanced, print YES, otherwise print NO

مثال‌ها🔗

ورودی نمونه ۱🔗

6
3H_2 + N_2 => 2NH_3
6CO_2 + 6H_2O => C_6H_{12}O_6 + 6O_2
3Ca(OH)_2 + 2H_3PO_4 => Ca_3(PO_4)_2 + 6H_2O
4H_2 + N_2 => 2NH_3
3CO_2 + 3H_2O => C_6H_{12}O_6 + O_2
Ca(OH)_2 + 2H_3PO_4 => Ca_3(PO_4)_2 + 2H_2O
Plain text

خروجی نمونه ۱🔗

YES
YES
YES
NO
NO
NO
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.