找每行最大数就行了
#include
using namespace std;
int main()
{
int l1,l2;
cin>>l1>>l2;
int max1=0,max2=0,temp;
for(int i=0;i
cin>>temp;
if(temp>max1)max1=temp;
}
for(int i=0;i
cin>>temp;
if(temp>max2)max2=temp;
}
cout<<(max1+max2);
return 0;
}
可以使用两个数组来分别存储两行整数,然后使用双重循环遍历两个数组中的所有数对,找到其中相加和最大的数对。具体实现步骤如下:
1. 定义两个数组a和b,分别存储第一行和第二行的整数。
2. 定义两个变量max_sum和max_index,分别表示当前找到的数对的最大和和对应的下标。
3. 使用双重循环遍历两个数组中的所有数对,计算其相加和。如果当前数对的相加和大于max_sum,则更新max_sum和max_index的值。
4. 遍历完所有数对后,max_index即为所找到的数对在数组中的下标。
下面是完整的C++代码实现:
```c++
#include
using namespace std;
int main() {
int a[100], b[100];
int n, max_sum = 0, max_index;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int sum = a[i] + b[j];
if (sum > max_sum) {
max_sum = sum;
max_index = i * n + j;
}
}
}
cout << "The pair with max sum is (" << a[max_index / n] << ", " << b[max_index % n] << "), and their sum is " << max_sum << endl;
return 0;
}
```
该代码首先从输入中读入两行整数,然后使用两个循环遍历所有数对,并记录其中相加和最大的数对的下标和相加和。最后输出最大和及其对应的数对。