1 // Problem#: 1007 2 // Submission#: 4893204 3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License 4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ 5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University 6 /*今天在实验室快要完成的时候刚好遇到关机,就在找到bug的时候,回来把bug一改就刚好做了,题目要求就是把一串字符串按照一定的顺序存入,诸如/* 1 2 3 4 5 7 /*10 9 8 7 6 8 /*11 12 13 14 15 9 /*20 19 18 17 16 10 11 然后输出就是 1 10 11 20 2 .。。。。。。。5 6 15 16 //这里的数字只是一个位置· 12 13 14 */ 15 #include<iostream> 16 #include<string> 17 #include<cstdio> 18 #include<iostream> 19 using namespace std; 20 int main(){ 21 int column; 22 while(cin>>column&&column){ 23 string s; 24 getchar(); 25 getline(cin,s,'\n'); 26 int len = s.length(); 27 while(len%column!=0){ 28 s = s + "x"; 29 len = s.length(); 30 } 31 len = s.length(); 32 int row = len/column; 33 char max[row][column]; 34 int base = 0; 35 for(int i=0;i<row;i++){ 36 if(i%2==0){ 37 for(int j=0;j<column;j++){ 38 max[i][j] = s[base]; 39 base ++; 40 } 41 } 42 else{ 43 for(int j=column-1;j>=0;j--){ 44 max[i][j] = s[base]; 45 base ++; 46 } 47 } 48 } 49 for(int i=0;i<column;i++){ 50 for(int j=0;j<row;j++){ 51 cout<<max[j][i]; 52 } 53 } 54 cout<<endl; 55 56 } 57 return 0; 58 }
本知识属于个人知识成果,如需转载,请邮件请求