#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
int k1, k2, k3, n1, n2, n3;
char s[1000],d[1000];
int s1[500],s2[500],s3[500];
int i;
while( scanf("%d %d %d",&k1,&k2,&k3) && k1!=0 && k2!=0 && k3!=0 )
{
scanf("%s",s);
n1 = n2 = n3 = 0;
memset(s1,0,sizeof(int)*100);
memset(s2,0,sizeof(int)*100);
memset(s3,0,sizeof(int)*100);
for( i = 0 ; s[i]!='\0' ; i++ )
{
if( s[i]>='a' && s[i]<='i' ) s1[n1++] = i ;
else if( s[i]>='j' && s[i]<='r' ) s2[n2++] = i ;
else s3[n3++] = i ;
}
s1[n1] = s2[n2] = s3[n3] = '\0';
memset(d,0,sizeof(char)*100);
for( i = 0 ; i < n1 ; i++ )
{
d[s1[(i+k1)%n1]] = s[s1[i]];
}
for( i = 0 ; i < n2 ; i++ )
{
d[s2[(i+k2)%n2]] = s[s2[i]];
}
for( i = 0 ; i < n3 ; i++ )
{
d[s3[(i+k3)%n3]] = s[s3[i]];
}
d[strlen(s)] = '\0';
printf("%s\n",d);
}
system("PAUSE");
return 0;
}
首先,遍历数组s,将一、二、三组字符的位置存在数组s1,s2,s3中,根据右旋规律,将s中的字符复制到d数组相应的位置,右旋的规律是
d[s1[(i+k1)%n1]] = s[s1[i]];
n1是s1的长度。