zoukankan      html  css  js  c++  java
  • set与map

    set,自动排序去重,没有二维set,只能用map

    #include <iostream>
    #include <set>
    
    using namespace std;
    
    int main()
    {
        set<int> s;
        int n;cin>>n;
        for(int i=0;i<n;i++)
        {
        	int x;cin>>x;
        	s.insert(x);
        }
        set<int>::iterator it=s.begin();
        
        for(;it!=s.end();it++)
        {
        	cout<<*it<<endl;
        }
        cout<<s.count(1);
        return 0;
    }
    

    map实现字符串统计

    #include<iostream>
    #include<set>
    #include<map>
    using namespace std;
    /*
    给定n个字符串,m个问题,统计每个问题询问的字符串出现的次数
    */
    int main()
    {
    	map<string,int>h;
    	int n,m;cin>>n>>m;
    	string s;
    	while(n--)
    	{
     		cin>>s;
    		h[s]++;
    	}
    	while(m--)
    	{
     		cin>>s;
    		if(h.find(s)==h.end())
    			cout<<"0"<<endl;
    		else
    			cout<<h[s]<<endl;
    	}
    	return 0;	
    }
    
  • 相关阅读:
    KMP
    Trie 树
    Miller-Rabin质数测试
    快速幂
    Matlab 对图片的二值化处理
    huffman tree
    hdu5512-Pagodas
    迷宫
    poj2488-A Knight's Journey【DFS】
    linux操作
  • 原文地址:https://www.cnblogs.com/forward-985/p/13885821.html
Copyright © 2011-2022 走看看