本文整理汇总了C++中stack::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ stack::empty方法的具体用法?C++ stack::empty怎么用?C++ stack::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack
的用法示例。
在下文中一共展示了stack::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pop
// Removes the element from in front of queue.
void pop(void) {
pushIntoQueue();
if (!queue.empty())
queue.pop();
}
示例2: isb
bool isb(stack<int> &vi, stack<int> &vj) {
printf("DEBUG isb\n");
return !vi.empty() && (vj.empty() || vj.top() > vi.top());
}
示例3: pop
void pop() {
if (s_1.empty()) {
transfere();
}
s_1.pop();
}
示例4: empty
bool empty(){
return s1.empty() && s2.empty();
}
示例5: main
int main()
{
while(~scanf("%d %d",&n,&m))
{
for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
GetRmq(); Bo = (int)sqrt(n);
for(int i = 1;i <= m; i++) scanf("%d %d",&S[i].L,&S[i].R),S[i].Id = i;
sort(S+1,S+m+1);
St.push(0);
for(int i = 1;i <= n;i++)
{
while(St.size() > 1 && a[St.top()] > a[i]) St.pop();
R[i] = St.top(); St.push(i);
}
while(!St.empty()) St.pop();
St.push(n+1);
for(int i = n;i>=1;i--)
{
while(St.size() > 1 && a[St.top()] > a[i]) St.pop();
L[i] = St.top(); St.push(i);
}
while(!St.empty()) St.pop();
memset(sumL,0,sizeof(sumL));
memset(sumR,0,sizeof(sumR));
sumR[1] =a[1];
for(int i = 2;i<=n;i++) sumR[i] = sumR[R[i]]+(1LL)*(i-R[i])*a[i];
sumL[n] = a[n];
for(int i = n-1;i >= 1;i--) sumL[i] = sumL[L[i]]+(1LL)*(L[i]-i)*a[i];
LL sum = 0;
int l = 0,r = 1;
for(int i = 1;i<=m;i++)
{
while(r <= S[i].R) sum +=Rcal(l,r),r++;
while(r > S[i].R+1) r --,sum-=Rcal(l,r);
while(l < S[i].L-1) l++,sum-=Lcal(l,r);
while(l >= S[i].L) sum+=Lcal(l,r),l--;
ans[S[i].Id] =sum;
}
for(int i = 1;i<=m;i++) printf("%lld\n",ans[i]);
}
return 0;
}
示例6: main
int main()
{
#ifdef fn
freopen(fn ".in", "r", stdin);
freopen(fn ".out", "w", stdout);
#endif
scanf("%s", s + 1);
n = strlen(s + 1);
for (int i = 1; i <= n; i++)
{
if (s[i] == '(' || s[i] == '[')
st.push(i);
if (s[i] == ')')
{
if (!st.empty() && s[st.top()] == '(')
{
pr[i] = st.top(), st.pop();
pr[pr[i]] = i;
}
else
{
while (!st.empty())
pr[st.top()] = -1, st.pop();
pr[i] = -1;
}
}
if (s[i] == ']')
{
if (!st.empty() && s[st.top()] == '[')
{
pr[i] = st.top(), st.pop();
pr[pr[i]] = i;
}
else
{
while (!st.empty())
pr[st.top()] = -1, st.pop();
pr[i] = -1;
}
}
}
while (!st.empty())
pr[st.top()] = -1, st.pop();
// for (int i = 1; i <= n; i++)
// printf("%d ", pr[i]);
// puts("");
for (int i = 1; i <= n; i++)
a[i] = a[i - 1] + (s[i] == '[');
int L = 0, R = -1, l = -1, r = -1, ans = 0;
for (int i = 1; i <= n;)
{
if (pr[i] == -1)
{
if (l != -1 && umax(ans, a[r] - a[l - 1]))
L = l, R = r;
l = -1, r = -1;
i++;
}
else
{
if (l == -1)
l = i;
r = pr[i];
i = pr[i] + 1;
}
}
if (l != -1 && umax(ans, a[r] - a[l - 1]))
L = l, R = r;
printf("%d\n", ans);
for (int i = L; i <= R; i++)
putchar(s[i]);
}
示例7: empty
bool empty(void) {
return input.empty() && output.empty();
}
示例8: reset
void reset(){
while(!s.empty()) s.pop();
while(!q.empty()) q.pop();
while(!pq.empty()) pq.pop();
isStack=1, isQueue=1, isPQueue=1;
}
示例9: test
void test() {
while (!min_stack.empty()) {
cout << min_stack.top() << endl;
min_stack.pop();
}
}
示例10: gol
void gol() {
while (!stk.empty())
stk.pop();
}
示例11: main
int main()
{
int n;
char ch;
while(cin>>n)
{
int i,j,k=0;
arry[0]=n;
ch=getchar();
while(ch!='\n')
{
cin>>arry[++k];
ch=getchar();
}
k++;
int flag=1,s;
for(i=0;i<k;i++)
{
if(arry[i]<0)
{
team1.push(arry[i]);
team2.push(arry[i]*(-1));
}
else if(arry[i]>0)
{
if(team2.empty())
{
flag=0;
break;
}
if(arry[i]!=team2.top())
{
flag=0;
break;
}
else
{
team2.pop();
s=0;
while(team1.top()>0)
{
s=s+team1.top();
team1.pop();
}
if(s>=arry[i])
{
flag=0;
break;
}
team1.pop();
team1.push(arry[i]);
}
}
}
if(!team2.empty()) flag=0;
if(flag) cout<<":-) Matrioshka!"<<endl;
else cout<<":-( Try again."<<endl;
while(!team1.empty())
team1.pop();
while(!team2.empty())
team2.pop();
}
return 0;
}
示例12: hasNext
/** @return whether we have a next smallest number */
bool hasNext() {
if(s.empty())
return false;
return true;
}
示例13: Restore
void MWinDeviceImpl::Restore()
{
assert(not mState.empty());
mRenderTarget->RestoreDrawingState(mState.top());
mState.pop();
}
示例14: front
int front() {
if (s_1.empty()) {
transfere();
}
return s_1.top();
}
示例15: findnearest
void findnearest(FILE *fout)
{
int x = root;
int nearest = -1;
double mind = 0x7FFFFFFF;
dfs2(x, nearest, mind);
if (nearest == -1)
{
nearest = stk.top();
mind = dist(kd[nearest].d, target);
}
while (!q.empty()) q.pop();
q.push(T(kd[nearest].d[0], kd[nearest].d[1], mind));
used[nearest] = nowi;
nown = 1;
while (!stk.empty())
{
int bp = stk.top();
stk.pop();
double maxd = q.top().dis;
if (kd[bp].lc == 0 && kd[bp].rc == 0)
{
if (used[bp]!=nowi && (nown < kmin || cmps(dist(kd[bp].d, target) - maxd) < 0))
{
used[bp] = nowi;
if (nown == kmin) q.pop();
q.push(T(kd[bp].d[0], kd[bp].d[1], dist(kd[bp].d, target)));
if (nown<kmin) nown++;
}
}
else
{
int s = kd[bp].split;
int psearch;
if (target[s] <= kd[bp].d[s])
{
psearch = kd[bp].lc;
if (psearch && vis[psearch] != nowi) stk.push(psearch);
if ( (nown<kmin || cmps(abs(kd[bp].d[s] - target[s]) - maxd) < 0))
{
psearch = kd[bp].rc;
if (psearch && vis[psearch] != nowi) stk.push(psearch);
}
}
else
{
psearch = kd[bp].rc;
if (psearch && vis[psearch] != nowi) stk.push(psearch);
if ( (nown<kmin || cmps(abs(kd[bp].d[s] - target[s]) - maxd) < 0))
{
psearch = kd[bp].lc;
if (psearch && vis[psearch] != nowi) stk.push(psearch);
}
}
if (used[bp]!=nowi && (nown<kmin || cmps(dist(kd[bp].d, target) - maxd) < 0))
{
used[bp] = nowi;
if (nown == kmin) q.pop();
q.push(T(kd[bp].d[0], kd[bp].d[1], dist(kd[bp].d, target)));
if (nown<kmin) nown++;
}
}
}
int cnt = 0;
while (!q.empty())
{
ans[++cnt] = q.top();
q.pop();
}
fprintf(fout, "%d\n",cnt);
fprintf(fout, "%d %d\n", target[0], target[1]);
for (int i = cnt; i >= 1; i--)
{
fprintf(fout, "%d %d %.8f\n", ans[i].d[0], ans[i].d[1], ans[i].dis);
}
}