求助,本地能过,测评0分,主要是这题用string存储能改不?
查看原帖
求助,本地能过,测评0分,主要是这题用string存储能改不?
225807
bobo_code楼主2020/8/14 23:39
#include<iostream>
using namespace std;
int n,cnt=0;
char pd='0';//判断是否为0或1 
int main()
{
	string str;
	getline(cin,str);
	n=str.length();//n:矩阵边长 
	struct hang{
		string st;
	}a[n];//结构体存储矩阵 
	a[0].st=str;
	
	for(int i=1;i<n;i++)
	{
		getline(cin,a[i].st); 
	}//输入矩阵 
	
	cout<<n<<' ';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i].st[j]==pd)
			{
				cnt++;
			}
			else 
			{
				cout<<cnt<<' ';
				cnt=1;
				if(pd=='0')	pd='1';
				else pd='0';
			}				
		}
	}
	cout<<cnt;
	return 0;
}

第一组数据 11111 00100 11111 00100 11111

5 0 5 2 1 2 5 2 1 2 5

2020/8/14 23:39
加载中...