Security Bijective Functions

  • + 0 comments

    C++ solution with std::map like a table of frequencies :

    #include <iostream>
    #include <map>
    
    using namespace std;
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int n;
        cin>>n;
        map<int,int> freqeuncy;
        bool isTrue = true;
        for(int i=0;i<n;i++){
            int t;
            cin>>t;
            if(freqeuncy.find(t)==freqeuncy.end()){
                freqeuncy[t] = 1;
            }else {
                isTrue = false;
            }
        }
        isTrue ? cout<<"YES" : cout<<"NO";
        cout<<endl;  
        return 0;
    }