Luogu P1469 Finding Chopsticks Problem Solving

topic portal

Sort them first, and then judge whether there are even numbers one by one. Note that the for loop needs i+=2.

#include<bits/stdc++.h>
using namespace std;
int n,a[10000010];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i+=2){
        if(a[i]!=a[i+1]){
            cout<<a[i];
            return 0;
        }
    }
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325268892&siteId=291194637