To and Fro

来源:互联网 发布:数据录入员有前途吗 编辑:程序博客网 时间:2024/06/08 07:20
// http://www.spoj.com/problems/TOANDFRO/#include <iostream>#include <string>#include <cstring>using std::cin;using std::cout;using std::endl;using std::string;using std::memset;int main(int argc, char* argv[]) {int cols;char result[200];cin >> cols;while (cols != 0) {string encryptedText;cin >> encryptedText;int rows = encryptedText.size() / cols;memset(result,0,200);int position = 1;int offset = rows;int index = 0;for (int i = 0; i < rows; i++) {for (int j = 0; j < cols; j++) {result[position-1] = encryptedText[index++];position += offset;}position += 1;position -= offset;offset = -offset;}cout << result;cout << endl;cin >> cols;}}

0 0
原创粉丝点击