随笔分类 -  字符串相关

摘要:Look-and-say Sequence PAT-1140 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<sstream> using name 阅读全文
posted @ 2020-09-19 19:14 Garrett_Wale 阅读(103) 评论(0) 推荐(0) 编辑
摘要:A Delayed Palindrome PAT-1136 我这里将数字转换为字符串使用的是stringstream字符串流 扩充:将字符串转换为数字可以使用stoi函数,函数头为cstdlib #include<iostream> #include<cstring> #include<string 阅读全文
posted @ 2020-09-19 17:39 Garrett_Wale 阅读(153) 评论(0) 推荐(0) 编辑
摘要:Google Recruitment PAT-1152 本题最需要注意的是最后输出要以字符串形式输出,否则可能会出现前导0的情况。 /** * @Author WaleGarrett * @Date 2020/9/18 21:14 */ import java.io.*; import java.u 阅读全文
posted @ 2020-09-18 21:42 Garrett_Wale 阅读(138) 评论(0) 推荐(0) 编辑
摘要:JSON查询 "201709 3" 纯字符串模拟,考的就是耐心和细心。可惜这两样我都缺。。。 include include include include include include include using namespace std; const int maxn=102; int n, 阅读全文
posted @ 2019-09-03 19:39 Garrett_Wale 阅读(228) 评论(0) 推荐(0) 编辑
摘要:URL映射 "CCF201803 3" include include include include include include include include include using namespace std; const int maxn=101; const int maxm=10 阅读全文
posted @ 2019-09-01 20:39 Garrett_Wale 阅读(204) 评论(0) 推荐(0) 编辑
摘要:元素选择器 "201809 3" 这里我只考虑了没有后代选择器的情况 include include include include include include using namespace std; string s[101]; int n,m; int main(){ cin n m; g 阅读全文
posted @ 2019-09-01 11:59 Garrett_Wale 阅读(226) 评论(0) 推荐(0) 编辑
摘要:消息传递口 "201903 4" 本题主要是利用队列进行模拟,因为一开始我没有注意到要按照顺序,所以一开始的解法错误。 include include include include include include include using namespace std; const int max 阅读全文
posted @ 2019-08-29 18:53 Garrett_Wale 阅读(207) 评论(0) 推荐(0) 编辑
摘要:Blue Jeans "HDOJ 3080" 本题使用的是KMP算法加暴力解决 首先枚举第一个字符串的所有子串,复杂度为O(60 60),随后再将每个子串和所有剩下的m 1个字符串比较,看是否存在这个子串 若所有的字符串都有该子串,则看是否是最长的,如果是等长的再看是否是字典序最小的。 本题我wa了 阅读全文
posted @ 2019-08-09 17:41 Garrett_Wale 阅读(516) 评论(0) 推荐(0) 编辑
摘要:Seek the Name, Seek the Fame "POJ 2752" 本题使用的算法还是KMP 最主要的片段就是前缀数组pi的理解,这里要求解的纸盒pi[n 1]有关,但是还是需要使用一个循环来依次找到前面符合的前缀(所谓符合就是可以保持既是前缀也是s的后缀的子串长度)。 include 阅读全文
posted @ 2019-08-09 12:11 Garrett_Wale 阅读(146) 评论(0) 推荐(0) 编辑
摘要:Power String "POJ 2406" 字符串压缩模板题,但是是求有多少个这样最短的子串可以组成s。 include include include include include using namespace std; const int N=10000001; int pi[N]; v 阅读全文
posted @ 2019-08-09 11:49 Garrett_Wale 阅读(134) 评论(0) 推荐(0) 编辑
摘要:Period "HDOJ 1358" 这题还是属于KMP算法的应用,属于字符串压缩问题。也就是在一个字符串s中寻找一个前缀,使得s可以被一份或者多份前缀子串t拷贝连接,也就是串接。 include include include include include using namespace std 阅读全文
posted @ 2019-08-09 11:12 Garrett_Wale 阅读(150) 评论(0) 推荐(0) 编辑
摘要:Cyclic Nacklace "HDOJ 3746" 本题还是使用KMP算法,需要使用到前缀数组 利用前缀数组计算最小循环节:即t=n pi[n 1]. 最后输出还需要的珠子,当然还有判断什么时候输出为0. include include include include using namespa 阅读全文
posted @ 2019-08-09 10:41 Garrett_Wale 阅读(159) 评论(0) 推荐(0) 编辑
摘要:剪花布条 "HDOJ 2087" 本题和 "hdoj 1686" 相似,唯一不同的是这里的子串一定要是单独的。所以在确定有多少个子串时不能用前面的方法。而是在循环时,只要找到一个子串,i就不是++,而是+=子串的长度。 include include include include using na 阅读全文
posted @ 2019-08-09 10:12 Garrett_Wale 阅读(101) 评论(0) 推荐(0) 编辑
摘要:Oulipo "HDOJ 1686" 本题的思路就是KMP,和HDOJ 1711思路一样,不再赘述详情可以看链接: "1711题解" include include include include include using namespace std; string a,b; int pi[101 阅读全文
posted @ 2019-08-09 09:54 Garrett_Wale 阅读(117) 评论(0) 推荐(0) 编辑
摘要:Number Sequence "HDOJ 1711" 1.这里使用的算法是KMP算法,pi数组就是前缀数组。 2.代码中使用到了一个技巧就是用c数组看成是复合字符串,里面加一个特殊整数位 1000006,因为它永远不会出现在数组中。 3.额外需要注意的就是,需要加快速输入输出语句,因为涉及到的数据 阅读全文
posted @ 2019-08-09 09:37 Garrett_Wale 阅读(142) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示