POJ1107 W's Cipher 简单模拟

该博客介绍了POJ1107的W's Cipher问题,这是一个涉及字母重新排列的字符串加密挑战。内容包括题目描述、样例输入输出以及解题思路。博主分享了AC代码(cpp实现),并表示正在整理详细题解。
摘要由CSDN通过智能技术生成

POJ1107 W’s Cipher

Description
先是将字母和下划线分为三类a~i,j~r,s~z和‘_’; 然后,独立地交换每组的字母,例如:对于 “_icuo_bfnwhoq_kxert”,第一组符号有{i,c,b,f,h,e},位置分别为{2,3,7,8,11,17},假设k1=2;那么第一组符号顺序变为{h,e,i,c,b,f},不过在原字符串中占有的位置还是{2,3,7,8,11,17},然后第二组······第三组······
这里写图片描述

这里写图片描述

Sample Input
2 3 1
_icuo_bfnwhoq_kxert
1 1 1
bcalmkyzx
3 7 4
wcb_mxfep_dorul_eov_qtkrhe_ozany_dgtoh_u_eji
2 4 3
cjvdksaltbmu
0 0 0

Sample Output
the_quick_brown_fox
abcklmxyz
the_quick_brown_fox_jumped_over_the_lazy_dog
ajsbktcludmv

题解
整理ing

AC_Code(cpp):

#include<iostream>
using namespace std;
struct mychar
{
    char character;
    int position;

};

void Decrypted(char encrypted[], int k1, int k2, int k3)
{
    char decrypted[100]="";
    mychar char1[100];
    mychar char2[100];
    mychar char3[100];
    int count1 = 0;
    int count2 = 0;
    int count3 = 0;
    int len = strlen(encrypted);
    for (int i = 0; i < len; i++)
    {
        if (encrypted[i] >= 's' || encrypted[i] == '_')
        {
            char3[count3].character = encrypted[i];
            char3[count3].position = i;
            count3++;
        }
        else if (encrypted[i] >= 'j')
        {
            char2[count2].character = encrypted[i];
            char2[count2].position = i;
            count2++;
        }
        else
        {
            char1[count1].character = encrypted[i];
            char1[count1].position = i;
            count1++;
        }
    }
    for (int i = 0; i < count3; i++)
    {
        decrypted[char3[(i + k3) % count3].position] = char3[i].character;
    }
    for (int i = 0; i < count2; i++)
    {
        decrypted[char2[(i + k2) % count2].position] = char2[i].character;
    }
    for (int i = 0; i < count1; i++)
    {
        decrypted[char1[(i + k1) % count1].position] = char1[i].character;
    }
    cout << decrypted << endl;
}

int main()
{
    int k1, k2, k3;
    char encrypted[100]="";
    while (cin >> k1 >> k2 >> k3 && (k1 + k2 + k3))
    {
        cin >> encrypted;
        Decrypted(encrypted, k1, k2, k3);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值