[acm]HDOJ 1200 To and Fro

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=1200 

简单字符串处理,找规律


 

 1 /*
 2 11509672    2014-08-21 11:32:55    Accepted    
 3 1200    0MS    380K    442 B    G++    空信高手
 4 */
 5 #include<iostream>
 6 #include<string>
 7 #include<cstdio>
 8 using namespace std;
 9 int main()
10 {
11     //freopen("input.txt","r",stdin);
12     string str;
13     int n,flag=1;
14     while(cin>>n && n!=0)
15     {
16         cin>>str;
17         int pnt;
18         for(int i=1;i<=n;i++)
19         {
20             flag=1;//重置左右
21             pnt=i;
22             while(pnt<=str.length())
23             {
24                 cout<<str[pnt-1];
25                 //左右分别讨论
26                 if(flag){pnt+=(2*n-2*i+1);flag=0;} 
27                 else {pnt+=(2*i-1);flag=1;}
28             }
29         }
30         cout<<endl;
31     }
32     return 0;
33 }

 

posted @ 2014-08-21 11:33  西芒xiaoP  阅读(299)  评论(0编辑  收藏  举报