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;
}