题目传送门:7970. Encoded Message
水题,输入的字符串长度一定是平方数
代码:
1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 5 int main(){ 6 int testcases; 7 cin >> testcases; 8 while(testcases--){ 9 string message; 10 cin >> message; 11 int len = message.length(); 12 int gap = sqrt(len); 13 for (int i = gap - 1; i >= 0; i--) { 14 for (int j = 0; j < gap; j++) { 15 cout << message[i + j * gap]; 16 } 17 } 18 cout << endl; 19 } 20 return 0; 21 }