题目描述:
解题思路:
题解:
#include<iostream> using namespace std; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a < b ? a : b; } int main() { int l = 0, n = 0, maxlen = 0, minlen = 0,p=0; cout << "输入l的值" << endl; cin >> l; cout << "输入n的值" << endl; cin >> n; for (int i = 1; i <= n; i++) { cout << "输入P的值" << endl; cin >> p; maxlen = max(maxlen, max(l - p + 1, p)); minlen = max(minlen, min(l - p + 1, p)); } cout << "最大值是" << maxlen << "最小值为" << minlen << endl; system("pause"); return 0; }