There was no problem with the idea, but it was done for nearly three hours, with 2 hours of commissioning
The experience has the following points:
- Must learn to debug, master the output of the intermediate amount of skills, to enhance the learning of GDB debugging
- Sometimes the code is wrong, and the result is correct (then the following common errors are summarized)
- can use the structure , do not use the array, error-prone (temporarily do not know why)
- Code to specification, the space should have
- Some non-canonical expressions, different compilers have different results, note that you should avoid using such statements
Like this problem main pit on the 3rd, after the attention to avoid
The following is the AC code
#include <cstdio>#include<stack>#include<cstring>#include<cctype>Const intmaxn= ++Ten;using namespacestd;CharEXPS[MAXN];structMatrix {intA, B; Matrix (intA =0,intb =0): A (a), B (b) {}}m[ -];stack<Matrix>s;intMain () {#ifdef DEBUG freopen ("6.3.in","R", stdin); #endif intN; scanf ("%d\r",&N); for(intI=0; i<n;i++){ Chars0[Ten]; CharC; scanf ("%c",&c); s0[0]=C; scanf ("%d%d\r\n", &m[s0[0] -'A'].A, &m[s0[0] -'A'].b); //printf ("%c%d%d\r\n", s0[0], m[s0[0]-' A '].a, m[s0[0]-' a '].b); } while(SCANF ("%s", exps) = =1){ intsum=0; intlen=strlen (EXPS); intok=1; for(intI=0; i<len;i++){ if(Isalpha (Exps[i])) {S.push (M[exps[i]-'A']); //printf ("Push%d%d \ n", m[exps[i]-' a '].a,m[exps[i]-' a '].b); } Else if(exps[i]==')') {Matrix m2=s.top (); S.pop (); //printf ("Pop%d%d \ n", m2.a, m2.b);Matrix M1 =s.top (); S.pop (); //printf ("Pop%d%d \ n", m1.a, m1.b); if(m1.b! = m2.a) {ok=0; Break;} Sum+ = m1.a * m1.b *m2.b; S.push (Matrix (m1.a, m2.b)); //printf ("Push%d%d \ n", m1.a, m2.b,); } } if(OK) printf ("%d\n", sum); Elseprintf"error\n"); } return 0;}
Example 6-3 Matrix Chain multiplication, Uva 442