Loading

蓝桥杯基础练习 查找整数 数列特征

查找整数 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;
}
posted @ 2021-01-17 16:45  longwind7  阅读(184)  评论(0编辑  收藏  举报