hrbust 2104 Encryption 【模拟+STL】

Encryption
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 65(41 users)Total Accepted: 41(39 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映射的赋值,我们不妨来这样设定:mp【A】=1,mp【B】=2,mp【C】=3,mp【D】=4;


然后在输入第二个串的时候,用一个pos【】数组记录其原先所在的位子,我们还拿样例一来说话,pos【1】=mp【D】=4;pos【2】=mp【A】=1;pos【3】=mp【B】=2;pos【4】=mp【C】=3;


然后输入最后一个加密串的时候,我们用结构体来存单词和相对应的位子。即:ans【i】.pos=pos【i】。


最后我们对结构体排序,按照pos排序,最后输出即可:

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<iostream>
using namespace std;
struct output
{
    char out[1004];
    int pos;
}ans[1005];
char a[1004][25];
int pos[1004];
int cmp(output a,output b)
{
    return a.pos<b.pos;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        map<string, int >mp;
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%s",&a[i]);
            mp[a[i]]=i+1;
        }
        char tmp[25];
        for(int i=0;i<n;i++)
        {
            scanf("%s",tmp);
            pos[i]=mp[tmp];
        }
        for(int i=0;i<n;i++)
        {
            scanf("%s",&ans[i].out);
            ans[i].pos=pos[i];
        }
        sort(ans,ans+n,cmp);
        int f=0;
        for(int i=0;i<n;i++)
        {
            if(f==0)
            printf("%s",ans[i].out);
            else printf(" %s",ans[i].out);
            f++;
        }
        printf("\n");
    }
}











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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值