c_cpp 设置语法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 设置语法相关的知识,希望对你有一定的参考价值。

#include <bits/stdc++.h>
using namespace std;

// #CPP_STL #Sets #BasicProblem
// https://www.geeksforgeeks.org/set-in-cpp-stl/



int main() {
    // A set stores elements in sorted order
    // Does NOT contain duplicates
    set<int> s;
    
    // =====(IMP)==========
    // use unordered_set if sorted order is not required
    s.insert(25);
    s.insert(25); // Only one 25 will be added to set
    s.insert(28);
    s.insert(22);
    s.insert(2);
    for(auto it=s.begin();it!=s.end();it++){
        cout<<*it<<" "; // *it = value at it
    }
    cout<<endl;
    
//================( find(element) )===========================
    // s.find returns iterator if found, else returns s.end()
    auto it=s.find(28);
    if(it!=s.end()){
        cout<<"28 is found"<<endl;
    }

//=================(find if an element is present)==================
// =================(s.count(element)==========================
    if (hashset.count(2) <= 0) {
        cout << "Key 2 is not in the hash set." << endl;
    }

//=================( erase(iterator) )=============================
    if(s.find(28)!=s.end()){ // check if element is present before trying to delete
        s.erase(s.find(28));  // trying to delete a non-existent element returns error 
    }
    
    for(auto it=s.begin();it!=s.end();it++){
        cout<<*it<<" "; // *it = value at it
    }
    cout<<endl;
    it=s.find(28);
    if(it!=s.end()){
        cout<<"28 is found"<<endl;
    }else{
        cout<<"28 is not found"<<endl;
    }
    
    it=s.find(38);
    if(it!=s.end()){
        cout<<"38 is found"<<endl;
    }else{
        cout<<"38 is not found"<<endl;
    }
    
	return 0;
}

以上是关于c_cpp 设置语法的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 地图语法

c_cpp 一些YACC语法

c_cpp 查找包含[({在语法上是否正确的)的表达式。

c_cpp 设置GLSL制服

c_cpp 设置GLSL制服

c_cpp Brickstor区域设置脚本