题目链接:http://www.codeforces.com/problemset/problem/155/A
题意:找到当前最大值或者最小值出现的次数。“当前”的意思差不多是a[i]大于所有a[j](j小于i)或者大于所有a[j]。
C++代码:
#include <iostream> using namespace std; int n, a[1100]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int Low = a[0], High = a[0], cnt = 0; for (int i = 1; i < n; i ++) { if (a[i] > High) { High = a[i]; cnt ++; } else if (a[i] < Low) { Low = a[i]; cnt ++; } } cout << cnt; return 0; }