2014-02-19 Code 備忘錄►Data Structure STEP5::Problem 0098 : 刮鬍匹配 http://web2.ck.tp.edu.tw/~step5/probdisp.php?pid=0098這題很簡單,其實先把0放到stack裡,如果放了1進去,就看他上一個是不是0,是就一起拔掉,不是就繼續堆上去,輸出。 1234567891011121314151617181920212223#include <cstdio>#include <cstdlib>#include <iostream>#define N 100001using namespace std;int ST[N],st=0;int main(int argc,char *argv[]){ int n,b; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&b); if(b==1&&st>0){ if(ST[st-1]==0){st--;} else ST[st++]=b; }else ST[st++]=b; } printf("%d\n",st); //test //system("pause"); return 0;} Newer STEP5::Problem 0106 : 2項式展開 Older STEP5::Problem 0084 : 神秘題