密文搜索-map容器+substr

https://www.luogu.com.cn/problem/P8630

///因为密码是打乱顺序的,所以只要字母个数对上就行
///用map存字母种类和个数
///vector存每行密码
///不用set,每行独立 

再考察一个字符串分割函数substr,map自动比较

#include
using namespace std;
#define N 100011
typedef  long long ll;
typedef pair pii;
string a,s;
int n;
int bo[15];
vector> b;///因为密码是打乱顺序的,所以只要字母个数对上就行
///用map存字母种类和个数
///vector存每行密码
///不用set,每行独立 
ll an;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a;
	cin>>n;
	for(int i=0;i>s;
		map w;
		for(int j=0;j<8;j++)
		{
			w[s[j]]++;
		}
		b.push_back(w);
	}
	for(auto c:b)
	{
		for(int i=0;i<=a.size()-8;i++)
		///字符串分割,看看这个字符串能对上几个密码 
		{
			map s;
			string x=a.substr(i,8);
			for(int j=0;j<8;j++)
			{
				s[x[j]]++;
			}
			if(s==c) an++;///map自动比较 
		}
	}
	cout<

你可能感兴趣的:(c++)