hrbust 2104 Encryption 【模拟+STL】
2016-04-20 12:51
337 查看
Encryption | ||||||
| ||||||
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");
}
}
相关文章推荐
- 移动 II
- 哈理工oj 2239 影子模仿术【图搜】【BFS+标记方向】
- hrbust 1214 哈理工oj 1214 方格取数【BFS广搜+dp】
- hrbust 哈理工oj 1541 集合划分【dp、0-1背包】
- hrbust 哈理工oj 2181 无聊的小明【数位DP】
- hrbust 哈理工oj 1330 邂逅【模拟】
- hrbust 1328 相等的最小公倍数(数论)
- hrbust 1396 射镖游戏(思维 背包)
- hrbust 1401 九连环(矩阵快速幂)
- Hrbust 题目列表【700题】-个人整理
- Hrbust 2302 Another Tree【思维+Dfs】
- Hrbust 1460 Highway Construction【树的直径】
- Hrbust 2319 Number Game【思维+优先队列】
- Hrbust 1537 安置囚犯【并查集+二维费用背包】
- Hrbust 2210 A Wonderful Concert【Dp】水题
- Hrbust 2250 开锁魔法III【Dp+long double】
- Hrbust 2065 萌萌哒十五酱的苹果~【树链剖分+线段树】
- 【大二最后两题】Hrbust 2064 萌萌哒十五酱的宠物~【思维+树链剖分 / 树上倍增LCA】
- Hrbust 2095 奶牛家谱【Dp】
- Hrbust 2295 方方正正【规律】