-1
文字列を 'r'個の場所で回転させようとしていますが、何らかの問題に直面しています。次のコードは機能です。 の場合:hello coding.
r=3
の後にはng.hello codi
になるはずです。ここでr個の文字列の回転
void fnc(){
char a[100],key;
int n,r,i,t=1,total=0,count,x;
cin>>n; //no. of test cases
while(t<=n){
cin>>r; //no. of rotations
cin.get();
cin.get(a,100);
for(i=0; a[i]!= '\0'; i++){
//cout<<a[i];
total++;
}
cout<<total;
for(i=0; i<r; i++){
key = a[total-1];
cout<<"key: "<<key<<endl;
for(i=total-2; i>=0; i--){
a[i+1] = a[i];
}
a[0] = key;
}
for(i=0; a[i]!= '\0'; i++){
cout<<a[i];
}
///cout<<a<<endl;
t++;
}
}
http://en.cppreference.com/w/cpp/algorithm/rotate実装を見てくださいあなたの好きなIDEで。 –