原理就是:先把行方向上的处理完了,再处理列方向,然后删除的行和列作一个标记,我标记到每行没列的第109个位置,但是代码效率不知道为什么稍微有点低,在改改说不定。还有方法就删除一行,把整个数组往前挪一位。
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int a[110][110] =
{ };
int n;
cin >> n;
int i, j, k;
int tm;
int sum = 0;
int current;
int N;
N = n;
while (N--)
{
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[i][j];
}
}
int m = n - 1;
while (m--)
{
for (i = 0; i < n; i++)
{
tm = 999999;
if (!a[i][109])
for (j = 0; j < n; j++)
{
if (!a[109][j])
if (a[i][j] < tm)
tm = a[i][j];
}
for (j = 0; j < n; j++)
{
a[i][j] -= tm;
}
}
for (j = 0; j < n; j++)
{
tm = 999999;
if (!a[109][j])
for (i = 0; i < n; i++)
{
if (!a[i][109])
if (a[i][