数据结构实际用法

1.map

unordered_map<int, int> primes;

    while (n -- )
    {
        int x;
        cin >> x;

        for (int i = 2; i <= x / i; i ++ )
            while (x % i == 0)
            {
                x /= i;
                primes[i] ++ ;//i是第一个p.first
            }

        if (x > 1) primes[x] ++ ;
    }
	LL res = 1;
    for (auto p : primes)//遍历
    {
        LL a = p.first, b = p.second;
        LL t = 1;
        while (b -- ) t = (t * a + 1) % mod;
        res = res * t % mod;
    }


#include<iostream>
#include<map>

using namespace std;
map<string,string> res;
int n;

int main()
{
    string a,b,c,d;
    cin>>a>>b>>c>>d;
    res[a]=b;
    res[c]=d;
    for(map<string,string>::iterator i=res.begin();i!=res.end();i++)
    {
        cout<<i->first<<' '<<i->second<<endl;
    }
    for(auto p:res)
    {
        string i=p.first,j=p.second;
        cout<<i<<' '<<j<<endl;
    }
    for(auto p:res)
    {
        //string i=p.first,j=p.second;
        cout<<p.first<<' '<<p.second<<endl;
    }
    for(auto p:res)
    {
        //string i=p.first,j=p.second;
        cout<<p.first<<" "<<p.second<<endl;
    }
    printf("%d\n",res.count(a));
    printf("%d\n",res.count(b));
    printf("%d\n",res.count(c));
    printf("%d\n",res.count(d));
}

2022个人训练赛0312 B - Misha and Changing Handles

#include<iostream>
#include<map>

using namespace std;
map<string,string> res;
int n;

int main()
{
    scanf("%d",&n);
    while(n--)
    {
        string s1,s2;
        cin>>s1>>s2;
        if(res.count(s1)==0)
        {
            res[s2]=s1;
        }
        else
        {
            res[s2]=res[s1];
            res.erase(s1);
        }
    }
    
    printf("%d\n",res.size());
    for(auto p:res)
    {
        cout<<p.second<<' '<<p.first<<endl;
    }
}

2.vector

vector<string> b[N];  //开了N个vector
vector<string> b(N); //只有一个vector vecotr容量为N

两个的意思是不一样的

3.set set中的值都不相同,并且已经排好序
注意set的遍历

题目链接

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

int n,x,y;
set<int> s;

int  rr(long long a,int b){
   if(a>n||b>10)
      return 0;
   s.insert(a);
   //printf("%d\n",a);
   rr(10*a+x,b+1);
   rr(10*a+y,b+1);
}

int main()
{
    cin>>n;
    
    for(x=0;x<9;x++)
        for(y=x+1;y<=9;y++)
            rr(0,0);
    
    //set<int>::iterator i;
    for(auto i=s.begin();i!=s.end();i++) printf("%d\n",*i);
            
    cout<<s.size()-1;
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值