HDU 1453(City hall)

基础题。

#include <iostream>
using namespace std;
const int MAXN = 205;

char mp[MAXN][MAXN]; //墙
int height[MAXN] = { 0 }; //各种高度的砖块数量

int main()
{
    int M, N;
    cin >> M >> N;
    for (int i = 0; i < M; i++)
    {
        for (int j = 0; j < N; j++)
            cin >> mp[i][j];
    }

    for (int j = 0; j < N; j++)
    {
        int h = 0; //当前砖块的高度
        for (int i = 0; i < M; i++)
        {
            if (mp[i][j] == '1')
            {
                ++height[h];
                h = 0;
            }
            else
            {
                ++h;
            }
        }
        if (h > 0)
            ++height[h];
    }

    for (int i = 1; i < MAXN; i++)
    {
        if (height[i] > 0)
            cout << i << " " << height[i] << endl;
    }
    return 0;
}

继续加油。

发布了326 篇原创文章 · 获赞 1 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Intelligence1028/article/details/105390327