classTrie{private:vector<Trie*> children =vector<Trie*>(26);bool is_end =false;public:Trie(){}voidinsert(string word){int n = word.size();Trie* node =this;for(int i =0; i < n; i++){if(node->children[int(word[i]-'a')]==nullptr){node->children[int(word[i]-'a')]=newTrie();}node = node->children[int(word[i]-'a')];}node->is_end =true;}boolsearch(string word){int n = word.size();Trie* node =this;for(int i =0; i < n; i++){if(node->children[int(word[i]-'a')]==nullptr){returnfalse;}node = node->children[int(word[i]-'a')];}return node->is_end;}boolstartsWith(string prefix){int n = prefix.size();Trie* node =this;for(int i =0; i < n; i++){if(node->children[int(prefix[i]-'a')]==nullptr){returnfalse;}node = node->children[int(prefix[i]-'a')];}returntrue;}};/*** Your Trie object will be instantiated and called as such:* Trie* obj = new Trie();* obj->insert(word);* bool param_2 = obj->search(word);* bool param_3 = obj->startsWith(prefix);*/
解题思路
简单模拟。
代码
#include <bits/stdc.h>
using namespace std;
long long g[2000000];
long long n;
int main()
{long long x,y,z,sum0,k0;scanf("%lld",&n);for(x1;x<n;x)scanf("%lld",&g[x]);for(x1;x<n;x){scanf(&qu…
Spring Security概述
1.什么是Spring Security?
Spring Security是一个Java框架,用于保护应用程序的安全性。它提供了一套全面的安全解决方案,包括身份验证、授权、防止攻击等功能。Spring Security基于过滤器链的概念,可以轻松地集成到任…