Clairewd’s message(密文转换)

来源:互联网 发布:苏宁易购秒杀软件 编辑:程序博客网 时间:2024/05/16 05:27

Clairewd’s message

Problem Description

Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important messages and she was preparing for sending it to ykwd. They had agreed that each letter of these messages would be transfered to another one according to a conversion table.
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

The first line contains only one integer T, which is the number of test cases.
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.
Hint
Range of test data:
T<= 100 ;
n<= 100000;

Output

For each test case, output one line contains the shorest possible complete text.

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;
}


原创粉丝点击