您的位置:首页 > 产品设计 > UI/UE

uestc 969 易位法字符串解密

2016-09-14 23:09 260 查看
题意:chinese

思路:就是按照题意模拟

题目链接:http://acm.uestc.edu.cn/#/problem/show/969

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cctype>
using namespace std;

const int maxn = 1005;

char a[30], s[1005], temp[1005];
int ran[30];
vector<node> v;
vector<char> v1;
struct node
{
char s[1005];
int val;

bool operator < (const node &rhs) const
{
return val < rhs.val;
}
};

int main()
{
int t;
scanf("%d", &t);
while (t--)
{
v.clear(), v1.clear();
scanf("%s%s", a, s);
int len1 = strlen(a), len2 = strlen(s);
int res = len2 / len1;
for (int i = 0; i < len1; i++)
{
ran[a[i] - 'A'] = i;
v1.push_back(a[i]);
}
sort(v1.begin(), v1.end());
node e;
for (int i = 0; i < len1; i++)
{
strncpy(e.s, s + i * res, res);
e.val = ran[v1[i] - 'A'];
v.push_back(e);
}
sort(v.begin(), v.end());
int cnt = 0;
while (cnt < res)
{
for (int i = 0; i < (int)v.size(); i++)
printf("%c", toupper(v[i].s[cnt]));
cnt++;
}
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息