Idea: We mainly need to open two arrays, one of which is the value before the number of storage changes, and the other is the value after the number of storage changes.
# Include <stdio. h> # include <string. h> # include <ctype. h> # include <stdlib. h> int main () {char STR [200]; while (gets (STR )! = NULL) {printf ("expression:"); puts (STR); char s [200]; memset (S, 0, sizeof (s )); int num1 [26], num2 [26], vis [26]; int CNT = 0; For (INT I = 0; I <strlen (STR); I ++) if (STR [I] = '+' | STR [I] = '-' | isalpha (STR [I]) s [CNT ++] = STR [I]; for (INT I = 0; I <26; I ++) {num1 [I] = I + 1; num2 [I] = I + 1; vis [I] = 0;} For (INT I = 0; I <CNT; I ++) {If (isalpha (s [I]) vis [s [I]-'a'] = 1; if (s [I] = '+' & S [I + 1] = '+' & isalpha (s [I + 2]) {vis [s [I + 2]-'a'] = 1; num1 [s [I + 2]-'a'] ++; num2 [s [I + 2]-'a'] ++; s [I] = '#'; s [I + 1] = '#';} if (s [I] = '-' & S [I + 1] = '-' & isalpha (s [I + 2]) {vis [s [I + 2]-'a'] = 1; num1 [s [I + 2]-'a'] --; num2 [s [I + 2]-'a'] --; s [I] = '#'; s [I + 1] = '#';} if (isalpha (s [I]) & S [I + 1] = '+' & S [I + 2] = '+ ') {vis [s [I]-'a'] = 1; num1 [s [I]-'a'] ++; s [I + 1] = '#'; s [I + 2] = '#';} If (isalpha (s [I]) & S [I + 1] = '-' & S [I + 2] = '-') {vis [s [I]-'a'] = 1; num1 [s [I]-'a'] --; s [I + 1] = '#'; s [I + 2] = '#' ;}} int flag = 1, sum = 0; For (INT I = 0; I <CNT; I ++) {If (isalpha (s [I]) & flag) {sum + = num2 [s [I]-'a']; flag = 0 ;} else if (s [I] = '+' | s [I] = '-') {If (s [I] = '+ ') {for (Int J = I; j ++) if (isalpha (s [J]) {sum + = num2 [s [J]-'a']; break ;}} if (s [I] = '-') {for (Int J = I; j ++) if (isalpha (s [J]) {sum-= num2 [s [J]-'a']; break ;}}} printf ("value = % d \ n", sum ); for (INT I = 0; I <26; I ++) {If (vis [I]) {printf ("% C = % d \ n ", I + 'A', num1 [I]) ;}} return 0 ;}