Clairewd’s message
2015-07-05 21:47
429 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4300
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int next1[100005];
char str[27];
char s1[100005],s2[100005];
void getnext(char *t)
{
int i = 0,j = -1;
next1[0] = -1;
while(t[i])
{
if(j == -1 || t[i] == t[j])
{
i++;
j++;
next1[i] = j;
}
else
j = next1[j];
}
}
int kmp(char *s,char *t)
{
int i = 0,j = 0;
int slen =strlen(s),tlen = strlen(t);
getnext(t);
while(j<tlen)
{
if(j == -1 || s[i] == t[j]) // tÊÇÃ÷ÎļÓÂÒÂ룬sÊǺóÃæÒ»°ëµÄÃ÷ÎÄ
{
i++;
j++;
if(i == slen)
return j;
}
else
j = next1[j];
}
return 0;
}
int main()
{
// freopen("C:\\Users\\John\\Desktop\\hi.txt","r",stdin);
int t,i;
cin >> t;
while(t--)
{
scanf("%s",str);
scanf("%s",s1);
int len = strlen(s1);
strcpy(s2,s1+(len+1)/2);
printf("%s",s1);
for(i = 0; s1[i]; i++)
{
for(int j = 0; j<26; j++)
{
if(s1[i] == str[j])
{
s1[i] = 'a'+j;
break;
}
}
}
int flag = kmp(s2,s1); //s1ÊÇÃ÷ÎļÓÂÒÂ룬s2ÊǺóÃæÒ»°ëµÄÃ÷ÎÄ
for(i = flag; i<len-flag; i++)
{
printf("%c",s1[i]);
}
cout << endl;
}
return 0;
}
http://acm.hdu.edu.cn/showproblem.php?pid=4300
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int next1[100005];
char str[27];
char s1[100005],s2[100005];
void getnext(char *t)
{
int i = 0,j = -1;
next1[0] = -1;
while(t[i])
{
if(j == -1 || t[i] == t[j])
{
i++;
j++;
next1[i] = j;
}
else
j = next1[j];
}
}
int kmp(char *s,char *t)
{
int i = 0,j = 0;
int slen =strlen(s),tlen = strlen(t);
getnext(t);
while(j<tlen)
{
if(j == -1 || s[i] == t[j]) // tÊÇÃ÷ÎļÓÂÒÂ룬sÊǺóÃæÒ»°ëµÄÃ÷ÎÄ
{
i++;
j++;
if(i == slen)
return j;
}
else
j = next1[j];
}
return 0;
}
int main()
{
// freopen("C:\\Users\\John\\Desktop\\hi.txt","r",stdin);
int t,i;
cin >> t;
while(t--)
{
scanf("%s",str);
scanf("%s",s1);
int len = strlen(s1);
strcpy(s2,s1+(len+1)/2);
printf("%s",s1);
for(i = 0; s1[i]; i++)
{
for(int j = 0; j<26; j++)
{
if(s1[i] == str[j])
{
s1[i] = 'a'+j;
break;
}
}
}
int flag = kmp(s2,s1); //s1ÊÇÃ÷ÎļÓÂÒÂ룬s2ÊǺóÃæÒ»°ëµÄÃ÷ÎÄ
for(i = flag; i<len-flag; i++)
{
printf("%c",s1[i]);
}
cout << endl;
}
return 0;
}
相关文章推荐
- leetcode:Contains Duplicate和Contains Duplicate II
- DELL R710在阵列卡上做raid的图例
- RAID损坏后 对数据的完整备份
- leetCode 11.Container With Most Water (数轴上容器) 解题思路和方法
- leetcode_219题——Contains Duplicate II(哈希表)
- A + B Again 2057 有符号的64进位的运算
- POJ 3250 Bad Hair Day(单调栈)
- leetcode 217:Contains Duplicate
- TIME_WAIT状态
- 【原创】CancellableWait
- leetcode 219:Contains Duplicate II
- 微软小冰发威,招摇人工智能
- select document library from certain list
- unity, trail renderer gone black on iOS
- rails 中使用association 生成select 下拉框的一些小技巧
- 图灵 数理逻辑 人工智能 图灵机与计算问题 论文
- LeetCode Contains Duplicate (判断重复元素)
- Leetcode#11 Container With Most Water
- 【Leetcode】Factorial Trailing Zeroes
- 人工智能的篱笆