查找整数 lx.lanqiao.cn/problem.page?gpid=T9
#include<iostream> using namespace std; int main() { int num, flag; cin >> num; int* x = new int[num]; for (int i = 0; i < num; i++) cin >> x[i]; cin >> flag; for (int i = 0; i < num; i++) { if (x[i] == flag) { cout << i + 1; return 0; } } cout << "-1"; return 0; }
数列特征 http://lx.lanqiao.cn/problem.page?gpid=T8
#include<iostream> using namespace std; int main() { int num, max, min, x, sum = 0; cin >> num; cin >> max; min = max; sum += max; for (int i = 0; i < num - 1; i++) { cin >> x; sum += x; if (x > max) max = x; if (x < min) min = x; } cout << max << endl; cout << min << endl; cout << sum; return 0; }