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;
}