/相当于看墙,投影之类的东西让我数多少个建筑物/
解释感觉还不到位,以后再看看
先强调这不是我原创的,只是加了注释。找到原作者后会加链接。以及改变布局

#include <cstdlib>
#include <cassert>
#include <stack>
using namespace std;
int main (void)
{
    int i, n, h, count;// 
    while ( scanf( "%d", &n ) != EOF )//多次 
    {
        stack<int>S;//创建了栈 
        count = 0;//建筑物的个数 
        for ( i = 0; i < n ; i ++ )
        {
            scanf( "%d", &h );//当前高度 
            while ( (!S.empty()) && (S.top()>h) )
            {
                count ++;
	            //如果栈中的大于就表示栈中就有一个,所以加1 
	            //相当于这样Nn(这N大于周围肯定有一个) 
                S.pop();
            }
            ``
            if ( S.empty() )//空了话肯定要收入了 
            {
                if ( h != 0 )
                    S.push(h);
            }
            else
            {
                if ( S.top() == h )//一样只需要存放一次高度就行 
                    continue;
                else if ( S.top() < h )
                    S.push(h);//nN(这时候不能保证所以先收入,如果后面一样) 
                else // S.top() > h(我当前认为是为了保险) 
                    assert(false);
            }
        }
        while ( !S.empty() )//多种参差不齐的高度 
        {
            count ++;
            S.pop();
        }
        printf( "%d\n",count );
    }
    return EXIT_SUCCESS;
}