## Bailian2819 W的密码【密码+模拟】

2819:W的密码

)。所有字符串最多有偿服务0个字符。ki 是1-100之间的整数。

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

the_quick_brown_fox
abcklmxyz
the_quick_brown_fox_jumped_over_the_lazy_dog
ajsbktcludmv

1107

本题与参考链接的题是同一题，代码可以直接AC。

AC的C语言程序如下：

``````/* POJ1107 ZOJ1042 UVALive2291 W's Cipher */

#include <stdio.h>
#include <string.h>

#define N 80
char s[N + 1], t1[N + 1], t2[N + 1], t3[N + 1], s1[N + 1], s2[N + 1];

void fix(char t[],int k,int len)
{
int i, j;
k = len - k % len;
for(i = 0; i < k; i++)
s1[i] = t[i];
s1[i]='\0';

for(i = k, j = 0; i < len; i++)
s2[j++] = t[i];
s2[j]='\0';
strcat(s2, s1);
strcpy(t, s2);
}

int main(void)
{
int k1, k2, k3, len, i1, i2, i3, i;
while(~scanf("%d%d%d", &k1, &k2, &k3) && (k1 || k2 || k3)) {
memset(t1, 0, sizeof(t1));
memset(t2, 0, sizeof(t2));
memset(t3, 0, sizeof(t3));

scanf("%s", s);
len = strlen(s);
i1 = i2 = i3 = 0;
for(i = 0; i < len; i++)
if(s[i] >= 'a' && s[i] <= 'i')  t1[i1++] = s[i];
else if(s[i] >= 'j' && s[i] <= 'r') t2[i2++] = s[i];
else if( (s[i] >= 's' && s[i] <= 'z' ) || s[i] == '_') t3[i3++] = s[i];

if(i1)
fix(t1, k1, i1);
if(i2)
fix(t2, k2, i2);
if(i3)
fix(t3, k3, i3);

i1 = i2 = i3 = 0;
for(i = 0; i < len; i++)
if(s[i] >= 'a' && s[i] <= 'i')  s[i] = t1[i1++];
else if(s[i] >= 'j' && s[i] <= 'r') s[i] = t2[i2++];
else if( (s[i] >= 's' && s[i] <= 'z' ) || s[i] == '_') s[i] = t3[i3++];

printf("%s\n", s);
}

return 0;
}``````