poj 2015 Permutation Code

本文介绍了一道关于模拟算法的题目,通过围绕已知条件进行模拟,实现字符串的匹配与替换。详细展示了使用C++实现该算法的具体过程,包括变量定义、函数设计与主流程控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一题简单的模拟题
    关键在于所有点全部都从已知d的周围开始模拟;

#include
#include
#include
#include
#include
#include
#include
using namespace std;

char a[100] , b[100] , c[100] , m[100];
int x , sizea , sizeb , sizec , n;

void fun(int y)
{
    int g = (y+1)%sizec , i , h  , f;
    for(i = 0 ; i < sizea ; i++)
        if(c[y] == a[i])  break;
    h = i;
    for(i = 0 ; i < sizea ; i++)
        if(m[g] == a[i])  break;
    f = i;
    for(i = 0 ; i < sizeb ; i++)
    {
        if(h == (f^i))  {m[y] = b[i]; return ;}
    }//printf("%d %d %d %d\n" , y , h , f , i);
}

int main()
{
    while(scanf("%d" , &x)  && x)
    {
        getchar();
        gets(a);
        gets(b);
        gets(c);
        sizea = strlen(a) , sizeb = strlen(b) , sizec = strlen(c);
        n = floor(sizec*sqrt(sizec*1.0)+x);
        n = n%sizec;
    //    cout<<n<<endl;
        int i , y;
        for(i = 0; i < sizea; i++)
            if(c[n] == a[i])  break;
        y = i;
        m[n] = b[y];
        if(sizec == 1)  {cout<<m[0]<<endl;  continue ;}
        for(i = n-1; i >= 0 ; i--)
            fun(i);
        for(i = sizec-1; i > n; i--)
            fun(i);
        m[sizec] = '\0';
        cout<<m<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值