HDU 4300 暴力水过

简介:

题意:给出一个26位的字母对照表,再给一段密文+明文(密文按照对照表翻译好的)的字符串,前面是明文后面是密文,而且密文一定完整明文可能不完整。让你把密文还原,还有个条件是密文尽可能短的,先输出密文输出明文。

因为密文完整明文可能不完整所以最短的情况也就行一半密文一半明文了,所以就先把这段文字按照表翻译成明文,在从头与给出的字符串的后半部分比较,对上了就说明是原串在这之前的部分是密文。

qwertabcde

(翻译后)abced.....

这样qwert就是密文,再把qwert翻译成明文就可以了。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
#define N 100005
char yl[30],data[N],data1[N],data2[N>>1];
int main()
{
    map<char,char>mymap;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        mymap.clear();
        scanf("%s%s",yl,data);
        for(int i=0; i<26; i++)
            mymap[yl[i]]='a'+i;
        int len=strlen(data),len1=len%2?len/2+1:len/2;
        for(int i=0; i<len1; i++)
            data1[i]=mymap[data[i]];
        for(int i=len1,j=0; i<len; i++,j++)
            data2[j]=data[i];
        int j=0;
        for(int i=0; i<len-len1; i++)
        {
            for(j=0; j+i<len-len1; j++)
                if(data1[j]!=data2[i+j])
                    break;
            if(i+j>=len-len1)
                break;
        }
        for(int i=0; i<len-j; i++)
            printf("%c",data[i]);
        for(int i=0; i<len-j; i++)
            printf("%c",mymap[data[i]]);
        puts("");
    }
    return 0;
}


目录
相关文章
|
5天前
Hopscotch(POJ-3050)
Hopscotch(POJ-3050)
|
9月前
UVa11420 - Chest of Drawers(动态规划)
UVa11420 - Chest of Drawers(动态规划)
31 0
poj-3094-quicksum
http://poj.org/problem?id=3094 很简单 #include #include using namespace std; int main() { string a; int sum=0; while(getline(cin...
552 0
POJ 2487 Stamps
Description Background Everybody hates Raymond. He’s the largest stamp collector on planet earth and because of that he always makes fun of all the others at the stamp collector parties.
1035 0
POJ 2027 No Brainer
Problem Description Zombies love to eat brains. Yum. Input The first line contains a single integer n indicating the number of data sets.
841 0
|
人工智能
POJ 1936 All in All
Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way.
759 0