您的位置:首页 > 其它

hrbust 2104 Encryption 【模拟+STL】

2016-04-20 12:51 337 查看
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");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息