1. 程式人生 > >CF 999 B. Reversing Encryption

CF 999 B. Reversing Encryption

color 知識 string bsp cstring name http encrypt reverse

題目地址

分析:

  規律:當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 }

CF 999 B. Reversing Encryption