摘要:manacher求最长子串。/*PROG : calfflacLANG : C++*/# include <cstdio># include <cctype># define N 20000 + 5int n;char s[N];int Min(int x, int y){ return x < y ? x : y;}int manacher(char *s, int len, int &st){ int n = len*2+1; char t[2 * N]; /* insert '#' in string s to form a 2*le
阅读全文
摘要:字符串,需要注意格式,和样例输出用fc命令比较,一致时就行了。# include <cstdio># include <cstring># include <cstdlib># include <cmath># define N 100 + 5# define M 60 + 5int n;char fname[N][M];int cmp(const void *x, const void *y){ return strcmp((char*)x, (char*)y);}int max(int x, int y){ return x>y ? x
阅读全文
摘要:字符串函数的应用。# include <cstdio># include <cstring># define RULESN 10 + 5# define MAXLEN 80 + 5int n;char src[RULESN][MAXLEN];char des[RULESN][MAXLEN];char text[4 * MAXLEN];void replace(char *t, char *s, char *d){ int len = strlen(s); char *p, tmp[4 * MAXLEN]; while (p = strstr(t, s)) { ...
阅读全文
摘要:枚举。第一次遇见:Your submission with number ***** for the problem 644 - Immediate Decodability has failed with verdict ./* 644 - Immediate Decodability*/# include <cstdio># include <cstring>int n;char s[10][15];bool in(char *p, char *t){ for (int i = 0; p[i]; ++i) if (!t[i] || p[i] != t[i]) re.
阅读全文
摘要:题目:给出一个整数n,问1-n之间包括n在内的所有数中49出现的次数。输入首先为一个整数T,表示接下来有T组输入。# include <cstdio># include <cstring># define N 10000000# define LEN 22typedef long long int LL;LL f[LEN][10];LL pow10[LEN];void init(void){ pow10[0] = 1; for (int i = 1; i < LEN; ++i) { pow10[i] = 10*pow10[i-1]; if (i>=...
阅读全文
摘要:按照 CSGrandeur 大牛的给出的方法做的;暴力即可;判断是否可以添加一个 字符得到时,有点小技巧,具体见代码;# include <stdio.h># include <string.h># define WL 17int n;char dic[10005][WL], word[WL];char exist(char *buf){ int i; for (i = 0; i < n; ++i) { if (strcmp(dic[i], word) == 0) return 1; } return 0;}char replace(char *x,...
阅读全文
摘要:这道题是字符串的模式匹配,要求计算出模式串在文本串中出现的次数,比如:"AZA" 在 "AZAZAZA" 中出现了 3 次;这道题使用 KMP 过的,但是 horspool 却不能过,尝试了一下各种方法后,还是回到了麻烦的 KMP,留下了以下几个模版:1. shift-or,据说比 KMP 快两倍,但只适用于模式串在 32 位以内,64位以内的也可以,需要把 b[] 改为 long long int 型,超出范围的可以尝试自己构造长类型……这道题不适用# include <string.h>int b[128]; /* int型共32位,模式
阅读全文
摘要:这道题貌似有陷阱:用gets过不了。 1 # include <stdio.h> 2 # include <ctype.h> 3 # include <string.h> 4 # include <stdlib.h> 5 6 # define MAX_LEN 205 7 # define MAXN 5005 8 9 char dic[MAXN][MAX_LEN];10 char word[MAX_LEN];11 12 int cmp(const void *a, const void *b);13 14 int main()15 {16 char
阅读全文
摘要:开始以为统计示例那句话中26个字母对应的字符串就行了,后来发现‘A’和‘a’不一样,仔细一看有一个位不一样,突然想到了ascii,一看7位,这不正好吗! 1 # include <stdio.h> 2 # include <string.h> 3 4 char str[15]; 5 char t[8] = {64, 32, 16, 8, 0, 4, 2, 1}; 6 7 int main() 8 { 9 short int i, c;10 11 gets(str);12 while (gets(str) != NULL)13 {14 ...
阅读全文
摘要:写的很繁琐。 1 # include <stdio.h> 2 # include <ctype.h> 3 4 # define MAX_WORD_LEN 25 5 # define MAX_LINE_LEN 75 6 # define MAXN 25 7 8 char keyw[MAXN][MAX_WORD_LEN]; 9 char line[MAXN][MAX_LINE_LEN];10 char copy[MAX_LINE_LEN];11 int cnt[MAXN];12 13 int key_cnt(char *line, int len, char *keywor
阅读全文
摘要:读取题目要求格式的字符串是个问题。 1 /* UVa 537 - Artificial Intelligence? */ 2 # include <stdio.h> 3 # include <ctype.h> 4 # include <stdlib.h> 5 6 typedef struct { 7 double val; 8 int vis; 9 }phy;10 11 phy U, I, P, x;12 int T;13 char tmp[50];14 15 void getval(void);16 17 int main()18 {19 int i...
阅读全文
摘要:考虑到每段串中字母顺序不能反序,没有使用栈;为了方便,也没有在输入的同时输出;感觉虽然麻烦点,但是如果加上思考的时间,是比较省时的做法。 1 /* UVa 10361 - Automatic Poetry */ 2 # include <stdio.h> 3 4 # define N 105 5 6 char L1[N], L2[N]; 7 int m[2], n[2]; 8 9 int main()10 {11 int T, i;12 13 scanf("%d", &T);14 getchar();15 while (T--)16 {17...
阅读全文
摘要:使用函数,结构会更清晰一些;fgets() 使用错,改为 scanf();边界判断错误(每一列下标都是从 0 开始,以 n-1 结尾),判断是否超出边界时,错写为 len*d[s][0];d[8][2] 的第5项错写成 {0,1}了。不管咋样,反正 AC 了。。 1 /* UVa 10010 - Where's Waldorf? */ 2 # include <stdio.h> 3 # include <string.h> 4 # include <ctype.h> 5 6 # define IN(up, x, low) (((x)<=(up)
阅读全文
摘要:要注意:单个字符是没有对应反序串的。几个测试: 1 NOTAPALINDROME -- is not a palindrome. 2 3 ISAPALINILAPASI -- is a regular palindrome. 4 5 2A3MEAS -- is a mirrored string. 6 7 ATOYOTA -- is a mirrored palindrome. 8 9 B -- is a regular palindrome.10 11 E -- is a regular palindrome.12 13 8 -- is a mirrored palindrome.我...
阅读全文