# 鞍点问题~帮忙差错~在线等~

youtwo__ 2008-04-19 01:51:28
#include <iostream>
using namespace std;

int main()
{
const size_t x = 4, y = 5;
int array[x][y], min_x, max_y;
size_t min_i = 0, max_j = 0;
bool judge = true;

cout << "输入一个二维数组("
<< x << "行" << y << "列):"
<< endl;

for (size_t ci = 0; ci != x; ++ci)
{
cout << "输入第" << ci + 1 << "行("
<< y << "个整数):" << flush;
for (size_t cj = 0; cj != y; ++cj)
{
cin >> array[ci][cj];
}
}

for (size_t i = 0; i != x; ++i)
{
size_t j = 0;
max_y = array[i][j];
for (/**/; j != y; ++j)
if (max_y < array[i][j])
{
max_y = array[i][j];
max_j = j;
}

size_t fi = 0;
min_x = array[fi][max_j];
for (/**/; fi != x; ++fi)
if (min_x > array[fi][max_j])
{
min_x = array[fi][max_j];
min_i = fi;
}

if (i == min_i)
{
cout << "第" << min_i + 1 << "行"
<< max_j + 1 << "列的整数："
<< array[min_i][max_j]
<< "是该数组的一个鞍点。"
<< endl;
judge = false;
}
}

if (judge)
{
cout << "该数组没有鞍点。" << endl;
}

return 0;
}

1 12 3 4 5
2 4 16 8 10
3 6 8 12 15
4 8 12 16 20

...全文
128 5 打赏 收藏 举报

5 条回复

youtwo__ 2008-04-19
• 打赏
• 举报

#include <iostream>
using namespace std;

int main()
{
const size_t x = 4, y = 5;
int array[x][y], min_x, max_y;
size_t min_i = 0, max_j = 0;
bool judge = true;

cout<< "输入一个二维数组(" << x << "行" << y << "列):" << endl;
for (size_t ci = 0; ci != x; ++ci)
{
cout << "输入第" << ci + 1 << "行("
<< y << "个整数):" << flush;
for (size_t cj = 0; cj != y; ++cj)
{
cin >> array[ci][cj];
}
}

for (size_t i = 0; i != x; ++i)
{
size_t j = 0;
max_y = array[i][j];
for (/**/; j != y; ++j)
if (max_y < array[i][j])
{
max_y = array[i][j];
max_j = j;
}

size_t fi = 0;
min_x = array[fi][max_j];
for (/**/; fi != x; ++fi)
{
if (min_x > array[fi][max_j])
{
min_x = array[fi][max_j];
min_i = fi;
}
}

if (i == min_i)
{
cout << "第" << min_i + 1 << "行"
<< max_j + 1 << "列的整数："
<< array[min_i][max_j]
<< "是该数组的一个鞍点。" << endl;
judge = false;
}

min_i = 0, max_j = 0; //真正的问题在这里~再次做外层循环以前没有再次将记录下标的值赋0
}

if (judge)
{
cout << "该数组没有鞍点。" << endl;
}
return 0;
}

//经本人再三思索我的思路是没有问题的~不过还是很感谢热心的EP啊~哈哈~
effective_person 2008-04-19
• 打赏
• 举报

``````
#include <iostream>
using namespace std;//在vs2005中
int main()
{
const size_t x = 4, y = 5;
int array[x][y], min_x, max_y;
size_t min_i = 0, max_j = 0;
bool judge = true;
cout<< "输入一个二维数组(" << x  << "行"  << y  << "列):" << endl;
for (size_t ci = 0; ci != x; ++ci)
{
cout  << "输入第"  << ci + 1  << "行("
<< y  << "个整数):"  << flush;
for (size_t cj = 0; cj != y; ++cj)
{
cin >> array[ci][cj];
}
}
int k=0;
size_t i = 0;//在此你的程序设计思路也好像有问题。你是对每一行进行遍历后在去考虑列。
//其实 应该把列和行同时考虑。
for (; i != x; ++i) //先考虑 每一列的最大值是在哪一行
{
size_t j = 0;
max_y = array[i][j];
for (/**/; j != y; ++j)
if (max_y  < array[i][j]) //这里少一个括号{ }还有输出问题自己改改吧！
{
max_y = array[i][j];
max_j = j;
}//找该行max_j
size_t fi = 0;
min_x = array[fi][max_j];
for (/**/; fi != x; ++fi) //考虑每一列。
{
if (min_x > array[fi][max_j])
{
min_x = array[fi][max_j];
min_i = fi;
}
if (i == min_i)
{
cout  << "第"  << min_i + 1  << "行"
<< max_j + 1  << "列的整数："
<< array[min_i][max_j]
<< "是该数组的一个鞍点。" << endl;
judge = false;
}
}
}
if (judge)
{
cout  << "该数组没有鞍点。"  << endl;
}
return 0;
}

``````
effective_person 2008-04-19
• 打赏
• 举报

``````

#include "stdafx.h"
#include <iostream>
using namespace std;//在vs2005中
int main()
{
const size_t x = 4, y = 5;
int array[x][y], min_x, max_y;
size_t min_i = 0, max_j = 0;
bool judge = true;
cout<< "输入一个二维数组(" << x  << "行"  << y  << "列):" << endl;
for (size_t ci = 0; ci != x; ++ci)
{
cout  << "输入第"  << ci + 1  << "行("
<< y  << "个整数):"  << flush;
for (size_t cj = 0; cj != y; ++cj)
{
cin >> array[ci][cj];
}
}
int k=0;
size_t i = 0;
for (; i != x; ++i)
{
size_t j = 0;
max_y = array[i][j];
for (/**/; j != y; ++j)
if (max_y  < array[i][j]) //这里少一个括号{ }还有输出问题自己改改吧！
{
max_y = array[i][j];
max_j = j;
}
size_t fi = 0;
min_x = array[fi][max_j];
for (/**/; fi != x; ++fi)
{
if (min_x > array[fi][max_j])
{
min_x = array[fi][max_j];
min_i = fi;
}
if (i == min_i)
{
cout  << "第"  << min_i + 1  << "行"
<< max_j + 1  << "列的整数："
<< array[min_i][max_j]
<< "是该数组的一个鞍点。" << endl;
judge = false;
}
}
}
if (judge)
{
cout  << "该数组没有鞍点。"  << endl;
}

return 0;
}

``````
Leejun527 2008-04-19
• 打赏
• 举报

youtwo__ 2008-04-19
• 打赏
• 举报

6.3w+

C++ 语言相关问题讨论，技术干货分享，前沿动态等
c++ 技术论坛（原bbs）

2008-04-19 01:51

1. 请不要发布与C++技术无关的贴子
2. 请不要发布与技术无关的招聘、广告的帖子
3. 请尽可能的描述清楚你的问题，如果涉及到代码请尽可能的格式化一下