• STL模板大全(第一弹)


    首先推荐一个网址“http://blog.jobbole.com/83461/”,其中详细记载了C++的模板元编程

    #include<iostream>
    using namespace std;
    
    struct Point{
        int x,y;
        Point(int x=0,int y=0):x(x),y(y){}
    };
    
    Point operator + (const Point &A,const Point &B){
        return Point(A.x+B.x,A.y,B.y);
    }
    
    ostream& operator << (ostream &out,const Point &p){
        out<<"("<<p.x<<","<<p.y<<")";
        return out;
    }//ostream表示输出流。。。
    //其中的point表示该类型
    //ostream表示的是cout这一操作
    //该操作为重载运算符操作
     
    
    template<typename T>
    T sum(T *begi,T *en){
        T *p=begi;
        T ans=0;
        for (T *p=begin; p!=end; p++)
            ans=ans+*p;
        return ans;
    }//紫书模板P106
    #include<iostream>
    #include<string>
    #include<set>
    #include<sstream>
    using namespace std;
    
    struct str{
        string s;
        bool operator<(const str &s1) const{
            return s.length()<s1.s.length();
        }
    };
    
    set<str> dict;
    
    string s,s2;
    int main(){
        while (cin>>s){
            for (int i=0; s[i]; i++)
            if (isalpha(s[i])) s[i]=tolower(s[i]);else s[i]=' ';
            stringstream ss(s);
            while (ss>>s2) dict.insert((str){s2});
        }
            for (set<str>::iterator i=dict.begin(); i!=dict.end(); i++)
                cout<<*i<<endl; 
        return 0;
    }//CE代码,打算向JS2XXX大佬请教
    #include<iostream>
    #include<string>
    #include<set>
    #include<sstream>
    using namespace std;
    
    set<string> dict;
    
    string s,s2;
    int main(){
        while (cin>>s){
            for (int i=0; s[i]; i++)
            if (isalpha(s[i])) s[i]=tolower(s[i]);else s[i]=' ';
            stringstream ss(s);
            while (ss>>s2) dict.insert(s2);
        }
            for (set<string>::iterator i=dict.begin(); i!=dict.end(); i++)
                cout<<*i<<endl; 
        return 0;
    }
    #include<iostream>
    #include<string>
    #include<cctype>
    #include<vector>
    #include<map>
    #include<algorithm>
    using namespace std;
    
    map<string,int> cnt;
    vector<string> words;
    vector<string> ans;
    string s;
    
    inline string rep(string s){
        string ans=s;
        for (int i=0; ans[i]; i++) ans[i]=tolower(ans[i]);
        sort(ans.begin(),ans.end());
        return ans;
    }
    
    int main(){
        while (cin>>s){
            if (s[0]=='#') break;
            words.push_back(s);
            string r=rep(s);
            if (!cnt.count(r)) cnt[r]=0;
            cnt[r]++;
        }
        for (int i=0; i<words.size(); ++i)
            if (cnt[rep(words[i])]==1) ans.push_back(words[i]);
        sort(ans.begin(),ans.end());
        for (int i=0; i<ans.size(); ++i)
            cout<<ans[i]<<endl;
        return 0;
    }
  • 相关阅读:
    20192415 202120222 《网络与系统攻防技术》实验七实验报告
    C#字符串压缩
    linux服务器登录mysql报错bash: mysql: command not found
    java读取含有合并单元格的Excel
    修改序列号:当序列号小于主键ID的时候如何处理?
    1130 is not allowed to connect to this MySql server
    报错: java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell
    报错:There is no getter for property named 'distinct' in
    报错:违反检查约束条件 (GYPTS.SYS_C0016857)
    vue代码如何实现平方米m2
  • 原文地址:https://www.cnblogs.com/leomessi-/p/7685370.html
Copyright © 2020-2023  润新知