本地的沈阳网站建设,网站备案回访电话号码,wordpress动态导航侧边栏,外贸进出口代理公司题干#xff1a; 编写一个程序#xff0c;读入一组整数#xff0c;这组整数是按照从小到大的顺序排列的#xff0c;它们的个数N也是由用户输入的#xff0c;最多不会超过20。然后程序将对这个数组进行统计#xff0c;把出现次数最多的那个数组元素值打印出来。如果有两个…题干 编写一个程序读入一组整数这组整数是按照从小到大的顺序排列的它们的个数N也是由用户输入的最多不会超过20。然后程序将对这个数组进行统计把出现次数最多的那个数组元素值打印出来。如果有两个元素值出现的次数相同即并列第一那么只打印较小的那个值。例如假设用户输入的是“100 150 150 200 250”则输出为150。输入: 6 100 150 150 200 200 250输出: 150
解题报告 乱搞。倒着遍历可以减少代码量。
AC代码
#includecstdio
#includeiostream
#includealgorithm
#includequeue
#includemap
#includevector
#includeset
#includestring
#includecmath
#includecstring
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX 2e5 5;
ll a[MAX];
int main()
{ll n;cinn;for(int i 1; in; i) cina[i];ll ans a[n],cnt1,tmpcnt 1;for(int i n-1; i1; i--) {if(a[i] a[i1]) {tmpcnt;}else tmpcnt 1;if(tmpcnt cnt) ans a[i],cnt tmpcnt;}cout ans endl;return 0 ;}