Beep beep Mile Mile 2019 autumn programming trick question --- three digital sum

 

 

 

 Problem solving: use c ++ multiset of the count and erase conduct problem-solving

The same type of subject: https://www.cnblogs.com/cstdio1/p/11377028.html

c ++ code is as follows:

#include <bits / STDC H ++.>
 the using  namespace STD;
 const  int N = 10000 + . 5 ; 
                
int n-, K, len = 0 ;
 int A [N]; 
multiset < int > S; // with the multiset contain duplicate element exists 
int main () 
{ 
    the while ( . 1 ) { 
    Scanf ( " % D " , & n-); // Note that the data input format of the     
    char C = getchar (); 
    a [len] = n-; 
    s.insert (a [ len]);     
    len ++;
    if(c==',')break;
    }    
    cin>>k;

    sort(a,a+len);
    for(int i=0;i<len;i++){
        s.erase(s.find(a[i]));
        for(int j=i+1;j<len;j++){
        s.erase(s.find(a[j]));
        if(s.count(k-a[i]-a[j])){
         cout<<"True"<<endl;
         return 0;    
        }
        s.insert(a[j]);
        }
        s.insert(a[i]);
    }cout<<"False"<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/cstdio1/p/11482674.html