回覆列表
  • 1 # nknus18199

    #include<iostream>usingnamespacestd;#defineMAX_SIZE50typedefstruct{intstack[MAX_SIZE];inttop;}Stack;intmain(){Stackst;st.top=-1;charch;boolflag=false;while(cin>>ch){switch(ch){case"(":st.stack[++st.top]=ch;break;case")":if(st.stack[st.top]=="("){st.top--;break;}else{cout<<"Dont"tmatch!"<<endl;flag=true;break;}case"[":st.stack[++st.top]=ch;break;case"]":if(st.stack[st.top]=="["){st.top--;break;}else{cout<<"Dont"tmatch!"<<endl;flag=true;break;}case"{":st.stack[++st.top]=ch;break;case"}":if(st.stack[st.top]=="{"){st.top--;break;}else{cout<<"Dont"tmatch!"<<endl;flag=true;break;}default:break;}if(flag){break;}}if(!flag){cout<<"matching!"<<endl;}return0;}簡單思路就是利用了棧,可以匹配3對括號,如果有什麼疑問可以再跟帖~~

  • 中秋節和大豐收的關聯?
  • 一快玉對著燈光看玉的上面一,層是金黃色的,這種玉是真是假?