分析:
规律:当i为n的倍数时,从0至i翻转(从前往后)
新知识: reverse(s+a,s+b);把字符串s中,地址从a到b间的内容反转
代码:
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 6 int main() 7 { 8 char s[105]; 9 int n; 10 cin >> n >> s; 11 for(int i = 1; i <= n; i++) 12 if(n%i == 0) 13 reverse(s,s+i); 14 cout << s << endl; 15 return 0; 16 }
原文地址:https://www.cnblogs.com/JiaaaaKe/p/9502495.html
时间: 2024-11-14 11:56:49