标签:
#include<iostream> using namespace std; int zuida(int n, int a[], int *sm, int *mm); void main() { int m, n, i, j, sm, mm, t2; int sum, max; int up[100], down[100], t[100]; int a[100][100], b[100]; cout << "输入二维数组的行" << endl; cin >> m; cout << "输入二维数组的列" << endl; cin >> n; for (i = 0; i<m; i++) { for (j = 0; j<n; j++) { cin >> a[i][j]; } } for (i = 0; i<m; i++) { for (j = 0; j<n; j++) { b[j] = a[i][j]; } sum = zuida(n, b, &sm, &mm); up[i] = sum; down[i] = mm; t[i] = sum; } t2 = t[0]; for (i = 0; i + 1<m; i++) { if (up[i] <= down[i + 1] && down[i] >= up[i + 1]) { t2 += t[i + 1]; } for (j = up[i]; j<up[i + 1]; j++) { if (a[i + 1][j]>0) t2 += a[i + 1][j]; //判别独立正数 } } cout << t2 << endl; } int zuida(int n, int a[], int *sm, int *mm) { int b[100] = { 0 }; int i, sum1 = 0, max1 = 0; for (i = 0; i<n; i++) { if (sum1<0) { sum1 = a[i]; } else { sum1 = sum1 + a[i]; } b[i] = sum1; } max1 = b[0]; for (i = 0; i<n; i++) { if (max1<b[i]) { max1 = b[i]; *mm = i; } } for (i = *mm; i >= 0; i--) { if (b[i] == a[i]) { *sm = i; break; } } return max1; }
4程序截图
5.总结
这个程序当时并没有写出来,后来也就不了了之了。这种做法是很不正确的,以后遇到问题和困难要学会解决,而不是放弃。
标签:
原文地址:http://www.cnblogs.com/gting/p/4581817.html