ZOJ1042
思路:把三種字符分別存儲,在+k1、+k2、+k3後取模
1.要考慮到k1>l1等情況
2.分母不能爲0,否則會出現 Floating Point Error
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
char str[1000000];
int main()
{
int k1,k2,k3;
int l1,l2,l3;
char s1[5000],s2[5000],s3[5000];
while(cin>>k1>>k2>>k3&&(k1+k2+k3))
{
cin>>str;
l1=l2=l3=0;
int len=strlen(str),i;
for(i=0;i<len;i++)
{
if(str[i]>='a'&&str[i]<='i')s1[l1++]=str[i];
else if(str[i]>='j'&&str[i]<='r')s2[l2++]=str[i];
else s3[l3++]=str[i];
}
// for(i=0;i<l1;i++)printf("*%c\n",s1[i]);
int p1,p2,p3;
//1.要考慮到k1>l1等情況
//2.分母不能爲0,否則會出現 Floating Point Error
if(k1>l1&&l1!=0)k1=k1%l1;
if(k2>l2&&l2!=0)k2=k2%l2;
if(k3>l3&&l3!=0)k3=k3%l3;
p1=l1-k1;
p2=l2-k2;
p3=l3-k3;
for(i=0;i<len;i++)
{
if(str[i]>='a'&&str[i]<='i'){
str[i]=s1[(p1++)%l1];
// cout<<str[i]<<endl;
}
else if(str[i]>='j'&&str[i]<='r')str[i]=s2[(p2++)%l2];
else str[i]=s3[(p3++)%l3];
}
cout<<str<<endl;
}
return 0;
}