Hust oj 2104 Encryption(map)

Encryption
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 69(44 users)Total Accepted: 45(42 users)Rating: Special Judge: No
Description

    Alice thinks it is very inconvenient to have to keep one of her keys in a public–private key pair secret. Therefore she invented a public–public key encryption scheme called the Really Secure Algorithm (RSA). The algorithm works as follows:

    A word is a sequence of between one and ten capital letters (A–Z). A sentence is a sequence of words, separated by spaces. The first public key is a sentence in which each word is used at most once. The second public key is a sentence formed by applying a permutation p to the words in the first public key. The plaintext (the unencrypted message) is a sentence that has exactly as many words as the public keys. (Unlike for the public keys, these words are not necessarily unique.) The ciphertext (the encrypted message) is the sentence formed by applying the permutation p to the plaintext.

    Given the two public keys and the ciphertext, recover the plaintext.

Input

On the first line one positive number: the number of test cases, at most 100. After that per test

case:

# one line with an integer n (1 <= n <= 1 000): the number of words in each sentence.

# one line with a sentence: the first public key.

# one line with a sentence: the second public key.

# one line with a sentence: the ciphertext.

All words consist of at least 1 and at most 10 uppercase letters.

Output

Per test case:

# one line with a sentence: the plaintext.

Sample Input
2
4
A B C D
D A B C
C B A P
3
SECURITY THROUGH OBSCURITY
OBSCURITY THROUGH SECURITY
TOMORROW ATTACK WE
Sample Output
B A P C
WE ATTACK TOMORROW
 
用map记录原来位置之后赋值给密文排序,得到的就是原文
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
#include<cmath>
using namespace std;

int t;
int n;
char str[15];
const int maxn = 1005;
int pos[maxn];

struct Str
{
    char a[15];
    int index;
}s[maxn];

int cmp(Str x,Str y)
{
    return x.index < y.index;
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        getchar();
        map<string ,int>Map;
        map<string ,int>::iterator it;

        for(int i=1;i<=n;i++)
        {
            scanf("%s",&str);
            Map[str] = i;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%s",&str);
            pos[i] = Map[str];
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%s",&s[i].a);
            s[i].index = pos[i];
        }
        sort(s+1,s+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            printf("%s",s[i].a);
            if(i != n)
                printf(" ");
        }
        printf("\n");
    }
}


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值