首页
DreamJudge
院校信息
考研初试
机试真题
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
西电机试专家
2025年3月24日 11:17
前缀字符串 题解:二刷优化代码,更易理解
P1098
回复 0
|
赞 3
|
浏览 377
#include <bits/stdc++.h> using namespace std; bool cmp(string a,string b){ return a.size()<b.size(); } int qian(string a,string b) {//a短b长 for(int i=0;i<a.size();i++) { if(a[i]!=b[i])//a非b前缀 ...
zxjrheaven
2025年3月23日 12:49
前缀字符串 题解:暴力
P1098
回复 0
|
赞 2
|
浏览 309
#include <bits/stdc++.h> using namespace std; struct node { string str; int len; }s[100]; bool cmp(node a,node b) { return a.len<b.len; } int main() { int n; while(cin>&g...
sheep276
2025年3月7日 18:39
前缀字符串 :用前缀树做的,WA,不知道为什么
P1098
回复 2
|
赞 6
|
浏览 536
#include <bits/stdc++.h> using namespace std; struct node { int num; node*next[26]; }; void init(node*&m) { for(int i=0;i<26;i++) {m->next[i]=NULL;} } void insert(node*&m,string a) { &nbs...
西电机试专家
2025年3月8日 09:36
前缀字符串 题解:暴力枚举
P1098
回复 0
|
赞 10
|
浏览 498
#include <bits/stdc++.h> using namespace std; //思路:暴力枚举,把符合要求的字符串存储到xin数组,若新数组中元素为原数组中字符串的前缀 //则更新xin数组中元素,使之越长越好,越长即越不容易成为别的字符串的前缀 ,若xin数组中元素 //与s[i] 中元素互不为对方前缀 ,则入数组 string s[100]; string xin[100]; bool is_pre(string a,string b){//判断a和b是否为对方的前缀 &nbs...
jsd
2025年2月6日 17:27
P1098 前缀字符串 答疑提问:
P1098
回复 2
|
赞 5
|
浏览 601
求助这个题,样例好多都无法通过,不知道哪里出了问题 #include<bits/stdc++.h> using namespace std; bool compare(string s1, string s2) { return s1.size() > s2.size(); } int main() { int n; while(cin>>n) { &n...
zcq107
2025年1月16日 12:23
前缀字符串 题解:
P1098
回复 2
|
赞 2
|
浏览 714
求助为何这样通过率为0,根据所有的字符串构造一棵Trie树,利用深度优先遍历寻找Trie树叶子节点的个数。由于示例“kdfa”是“kdfa”的前缀,故统计到叶子节点时,只有cnt[p]==1时才将该字符串统计进去,避免了相同字符串的统计。测试用例在本地ide中能够正确表示,求指教,本代码还有什么问题? //Trie树 #include<bits/stdc++.h> using namespace std; const int N = 100010; int son[N][26],cnt[N],idx = 1...
等等
2024年4月14日 21:19
前缀字符串 有大佬可以帮忙看一下错在哪里吗?
P1098
回复 2
|
赞 4
|
浏览 1.4k
#include<bits/stdc++.h> using namespace std; bool compair(const string& s1, const string& s2){ if (s1.size() > s2.size()) return false; // s1 不能是 s2 的前缀 for (int i = 0; i < s1.size(); i++) { if (s1[i] != s2[i...
624530017
2023年7月29日 13:13
前缀字符串 题解:构建前缀树做法C++
P1098
回复 0
|
赞 17
|
浏览 2.3k
构建前缀树做法 #include "iostream" #include "cstdio" #include "cstring" using namespace std; struct Node{ int count; Node* child[26]; Node(){ count=0; memset(child, 0,sizeof(child)); } }; //字符串加入前缀树中 void insertTree(string s,Node* root){ if(s.em...
AlbertTuring
2023年6月29日 19:19
C++简单模拟
P1098
回复 0
|
赞 14
|
浏览 1.7k
题目数据范围很小,可以直接暴力枚举做,时间复杂度O(n^2) #include<iostream> #include<cstring> using namespace std; const int N = 200; string s[N]; string h[N]; bool is_pre(string s1, string s2) { bool flag = true; string a, b; if(s1.size()<s2.size()) a = s1, b = s2; else ...
老猫
2021年1月20日 16:40
打卡
P1098
回复 1
|
赞 3
|
浏览 10.3k
教程代码 //1161 //通不过的代码,主要是creat_tree部分,写法不一样 #include<iostream> #include<string> #include<cstring> #include<stack> #include<vector> #include <queue> #include <functional> using namespace std; const int maxn=26; typedef struct TrieNode{ int...
1
2
题目
前缀字符串
题解数量
14
发布题解
在线答疑
热门题解
1
前缀字符串 题解:构建前缀树做法C++
2
C++简单模拟
3
巧妙的题解
4
前缀字符串 题解:暴力枚举
5
用map的做法
6
前缀字符串 :用前缀树做的,WA,不知道为什么
7
P1098 前缀字符串 答疑提问:
8
c
9
边建Trie树边删多余前缀
10
前缀字符串 有大佬可以帮忙看一下错在哪里吗?