题干
c++实现
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <map>
# include <string>
# include <vector>
using namespace std;
void Partition ( string & str, vector< int > & vec1, vector< int > & vec2, vector< int > & vec3) {
int i;
for ( int i = 0 ; i < str. size ( ) ; i++ ) {
if ( str[ i] >= 'a' && str[ i] <= 'i' ) {
vec1. push_back ( i) ;
}
else if ( str[ i] >= 'j' && str[ i] <= 'r' ) {
vec2. push_back ( i) ;
}
else {
vec3. push_back ( i) ;
}
}
}
void rightRotate ( string & str, vector< int > vec, int offset) {
vector< char > tmp;
for ( int i = vec. size ( ) - offset; i < vec. size ( ) ; i++ )
{
tmp. push_back ( str[ vec[ i] ] ) ;
}
for ( int i = vec. size ( ) - offset - 1 ; i >= 0 ; i-- )
{
str[ vec[ i + offset] ] = str[ vec[ i] ] ;
}
for ( int i = 0 ; i < tmp. size ( ) ; i++ )
{
str[ vec[ i] ] = tmp[ i] ;
}
}
int main ( ) {
string str;
int k1, k2, k3;
while ( scanf ( "%d%d%d" , & k1, & k2, & k3) != EOF ) {
if ( k1 == 0 && k2 == 0 && k3 == 0 ) {
break ;
}
char arr[ 1000 ] = { 0 } ;
scanf ( "%s" , arr) ;
str = arr;
vector< int > vec1, vec2, vec3;
Partition ( str, vec1, vec2, vec3) ;
rightRotate ( str, vec1, k1) ;
rightRotate ( str, vec2, k2) ;
rightRotate ( str, vec3, k3) ;
printf ( "%s\n" , str. c_str ( ) ) ;
}
return 0 ;
}