第一题:选择出现偶数次的最大的四个数(4个or2+2个) 第二题:假设输入一个数组a,用一个数组b保存a,然后将b进行排序,逆序找,如果相同就直接continue,否则ans++。 #include <bits/stdc++.h> using namespace std; const int MAXN = 1e5+5; typedef long long LL; int a[MAXN],b[MAXN]; int main() { int n; cin>>n; for(int i=0; i<n; i++) { cin>>a[i]; b[i] = a[i]; } sort(b, b+n); int ans = 0; for(int i=n-1; i>=0; i--) if(a[i] != b[i+ans]) ans++; cout<<ans<<endl; return 0; }
点赞 3

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务