欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > c/c++ >内容正文

c/c++

CSP认证201612-1中间数[C++题解]:遍历

发布时间:2025/4/5 c/c++ 29 豆豆
生活随笔 收集整理的这篇文章主要介绍了 CSP认证201612-1中间数[C++题解]:遍历 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

题目分析


来源:acwing

分析: 统计大于它和小于它的个数即可。

AC代码

#include<bits/stdc++.h> using namespace std; const int N = 1010; int n; int a[N];int main(){cin >> n;for(int i = 0; i < n; i ++) cin >> a[i];bool flag = false;for(int i = 0; i < n; i ++){int up = 0, down = 0;int t = a[i];for(int j = 0; j < n; j ++){if(a[j] > t) up ++;else if ( a[j] < t) down++;}if( up == down){cout << t << endl;flag = true;break;}}if(!flag) puts("-1"); }

题目链接

https://www.acwing.com/problem/content/3240/

总结

以上是生活随笔为你收集整理的CSP认证201612-1中间数[C++题解]:遍历的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。