标签:style blog color os io for ar div log
给你一个字符串,让你找出长度最长的字符串的个数(字符串可以不同)
#include <iostream> #include <utility> #include <stack> #include <cstdio> #define LMT 1000003 using namespace std; int len,ans; char bra[LMT]; int l[LMT]; //û?п???????? ()()()() int main() { len=-1;ans=0; int bl,pre,prel; scanf("%s",bra); stack < pair<char,int> > st; pair<char,int> t; for(int i=0;bra[i];i++) { if(!st.empty()) t=st.top(); if(!st.empty()&&t.first==‘(‘&&bra[i]==‘)‘) { st.pop(); bl=i-t.second+1; bl+=l[t.second-1]; l[i]=bl; if(bl>len) { ans=1; len=bl; } else if(bl==len) ans++; } else st.push(make_pair(bra[i],i)); } if(ans==0)printf("0 1\n"); else printf("%d %d\n",len,ans); return 0; }
标签:style blog color os io for ar div log
原文地址:http://www.cnblogs.com/Susake/p/3935738.html