uestc 969 易位法字符串解密

題意: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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章