这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。
题目地址: http://coder.buct.edu.cn/oj/Problem.aspx?pid=1052 有点小麻烦的一题
// buct 1052
// hash
#include
#include
#include
#include
using namespace std;
char aMatrix[205][205];
int hash[201];
int main()
{
//freopen("input.txt", "r", stdin);
int m, n;
scanf("%d %d", &m;, &n;); // m-竖,n-横
for(int i=0; i<=m; ++i)
for(int j=0; j<=n; ++j)
aMatrix[i][j] = '0';
getchar(); // ....
for(int i=1; i<=m; ++i)
{
for(int j=1; j<=n; ++j)
scanf("%c", &aMatrix;[i][j]);
getchar(); //....
}
/*
for(int i=0; i<=m; ++i)
{
for(int j=1; j<=n; ++j)
printf("%c", aMatrix[i][j]);
printf("\n");
}
*/
for(int j=1; j<=n; ++j)
{
int cnt=0;
for(int i=1; i<=m; ++i)
{
if(aMatrix[i][j]=='0' && aMatrix[i-1][j]=='0')
{
//cout << "no1" << "i=" << i << endl;
cnt++;
//printf("%d %d\n",cnt, hash[cnt]);
}
else if(aMatrix[i][j]=='0' && aMatrix[i-1][j]!='0')
{
//cout << "no2" << "i=" << i << endl;
hash[cnt]++;
//printf("%d %d\n",cnt, hash[cnt]);
cnt=1;
}
if(i==m)
{
//cout << "no3" << "i=" << i << endl;
hash[cnt]++;
//printf("%d %d\n",cnt, hash[cnt]);
}
}
cnt=0;
}
for(int i=1; i<=200; ++i)
if(hash[i])
printf("%d %d\n", i, hash[i]);
return 0;
}