随笔分类 -  字符串处理

摘要:题意给定一个由NC个字母组成的字符串,求长度为N的不同子串的个数思路:由于只有NC个字母,可以将字母编号,0 ~ NC - 1,转换成数字,就可以将字符串表示成NC进制的数字,这样所有字串代表的数字都是唯一的,转换成10进制的数也是唯一的!就像10的二进制表示只有1010例如3 4daababacd = 3a = 0b = 1c = 2daa = 3 * 4 ^ 2 + 0 * 4 ^ 1 + 0 * 4 ^ 0 = 48#include <stdio.h>#include <string.h>char str[1000000];bool hash[16000000] 阅读全文
posted @ 2011-04-19 16:50 L.. 阅读(680) 评论(0) 推荐(0)
摘要:题意判断一组字符串中是否出现自己的前缀子串思路字典树#include <stdio.h>#include <string.h>const int MAXN = 100010;struct dicTree{ int next[10]; bool isWord; void init(){ memset(next,-1,sizeof(next)); isWord = false; }};dicTree tree[MAXN];int num; bool ok;void insert(char *s){ int index = 0 ,level = 1; while( *s ){ 阅读全文
posted @ 2011-04-19 16:14 L.. 阅读(246) 评论(0) 推荐(0)
摘要:#include<stdio.h>int main(){ char input; while( (input = getchar()) != '#') { switch(input) { case ' ' : printf("%s","%20"); break; case '!' : printf("%s","%21"); break; case '$' : printf("%s","%24"); b 阅读全文
posted @ 2011-04-18 01:03 L.. 阅读(152) 评论(0) 推荐(0)
摘要:/*用指针写的最基本的字典树最基本的字典树释放内存也没写,第一题字典树 */#include <stdio.h>#include <stdlib.h>#include <string.h>const int MAXN = 100000;struct Trie{ int n; //记录走过这条路径的单词数量 struct Trie *next[26];};Trie *root;void init(Trie *t){ //初始化函数 所有孩子节点置为空 for(int i = 0; i < 26; i++){ t -> next[i] = NULL; 阅读全文
posted @ 2011-04-11 01:39 L.. 阅读(159) 评论(0) 推荐(0)
摘要:#include"stdio.h"#include"ctype.h"#include"string.h"#include"stdlib.h"int n,max = -1,maxI;char str[80],telNum[100000][9];char map[27] = "22233344455566677778889999";int cmp(const void *a,const void *b){ return (strcmp((char*)a,(char*)b));}void toNum( 阅读全文
posted @ 2011-04-10 06:40 L.. 阅读(115) 评论(0) 推荐(0)