Clairewd’s message(密文转换)
来源:互联网 发布:苏宁易购秒杀软件 编辑:程序博客网 时间:2024/05/16 05:27
Clairewd’s message
Problem Description
Unfortunately, GFW(someone's name, not what you just think about) has detected their action. He also got their conversion table by some unknown methods before. Clairewd was so clever and vigilant that when she realized that somebody was monitoring their action, she just stopped transmitting messages.
But GFW knows that Clairewd would always firstly send the ciphertext and then plaintext(Note that they won't overlap each other). But he doesn't know how to separate the text because he has no idea about the whole message. However, he thinks that recovering the shortest possible text is not a hard task for you.
Now GFW will give you the intercepted text and the conversion table. You should help him work out this problem.
Input
Each test case contains two lines. The first line of each test case is the conversion table S. S[i] is the ith latin letter's cryptographic letter. The second line is the intercepted text which has n letters that you should recover. It is possible that the text is complete.
T<= 100 ;
n<= 100000;
Output
Sample Input
2abcdefghijklmnopqrstuvwxyzabcdabqwertyuiopasdfghjklzxcvbnmqwertabcde
Sample Output
abcdabcdqwertabcde
/*题意是首先给一个26个字母组成的转换表s,字母表中的第i个字母的密文是s[i]
例如:qwertyuiopasdfghjklzxcvbnm转换表给出的a的密文为q,b的密文为w,依次类推c的为e
再给出一个字符串,代表截取的信息。信息=密文+明文;信息并不一定是完整的,但密文肯定是完整的,所以至少可以
判断前面的一半为密文,然后依次往后搜索看能否增加密文的长度,这样可以翻译的明文就越多。
*/
#include"stdio.h"
#include"string.h"
char cip[500001],conv[26];
int main()
{
int n,len,i,j,k,flag,flag1,temp;
while(scanf("%d",&n)!=EOF)
{
memset(conv,0,sizeof(conv));
memset(cip,0,sizeof(cip));
getchar();
while(n--)
{
scanf("%s",conv);
scanf("%s",cip);
len=strlen(cip);
j=0;
flag1=0;
if(len%2==0) //在这里要判断一下截取的信息的长度是否为奇数,如果为奇数 则要从一半的后面一个字母开始,不然最后一个会与中间的比较,这样中间的就比较了两次
temp=len/2;
else
temp=len/2+1;
for(i=temp;i<len;i++)
{
if(conv[cip[i]-'a']!=cip[j])
continue;
else
{
flag=0;
j++;
for(k=i+1;k<len;k++)
{
if(conv[cip[k]-'a']!=cip[j++])
{
flag=1;
break;
}
}
if(flag==0)
{
flag1=1;
break;
}
} //else
} //for
int y,x;
for(y=0;y<i;y++)
printf("%c",cip[y]);
for(y=0;y<i;y++)
{
for(x=0;x<26;x++)
if(cip[y]==conv[x])
printf("%c",x+'a');
}
printf("\n");
}
}
return 0;
}
- Clairewd’s message(密文转换)
- HDU4300:Clairewd’s message
- Clairewd’s message +KMP
- Clairewd’s message (KMP)
- Clairewd’s message
- hdu4300---Clairewd’s message
- hdu4300 Clairewd’s message
- Clairewd’s message
- Clairewd’s message
- HDU4300 Clairewd’s message
- 4300.Clairewd’s message
- 1002: Clairewd’s message
- Clairewd’s message
- Clairewd’s message
- HDOJ 4300 Clairewd’s message
- 【KMP】 hdu4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- hdu 4300 Clairewd’s message
- iOS开发那些事-iOS常用设计模式–委托模式案例实现
- 华为:给定一个数组input[],如果数组长度n为奇数,则将数组中最大的元素放到 output[]数组最中间的位置,如果数组长度n为偶数。。
- 动态规划+之基础递推+noj三角形
- JavaScript初学者应注意的七个细节
- android 底部选项卡(TabHost)
- Clairewd’s message(密文转换)
- mysql小参考
- 编写程序,用起泡法对10个数排序(按由小到大顺序) (C++版)
- Struts2的iterator标签遍历Map
- android 音乐播放器汇总
- xml文件解析
- android 修改Layout背景的颜色
- 2013/4/16
- 总结主流搜索引擎在服务型关键字上的表现