跳到正文

个人记录

9

team01bcm123约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年8月7日
收录
2026年8月7日
更新
2026年8月28日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;

int a[101][101];

int main()
{
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin >> a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		int cnt=0;
		int pos1=-1,pos2=-1;
		for(int j=1;j<=n;j++)
		{
			if(a[i][j]==1)
			{
				cnt++;
				if(cnt==1)pos1=j;
				if(cnt==2)pos2=j;
			}
		}
		if(cnt>=2)
		{
			for(int j=pos1+1;j<pos2;j++)
			{
				if(a[i][j]==0)a[i][j]=2;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}
原文