http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack> using namespace std; int main()
{
int n,cas=;
while(~scanf("%d",&n))
{
int i;
stack<int> stk;
stk.push(-);
int ans = ;
for(i=;i<n;i++)
{
int temp;
scanf("%d",&temp);
while(stk.top()>temp)
{
stk.pop();
}
if(stk.top()!=temp)
{
stk.push(temp);
if(temp!=) ans++;
}
}
while(!stk.empty()){stk.pop();}
printf("Case %d: %d\n",cas++,ans);
}
return ;
}