首页 > 其他 > 详细

BestCoder Round #43 pog loves szh I (字符串处理)

时间:2015-06-08 00:59:48      阅读:180      评论:0      收藏:0      [点我收藏+]

 

题意:设有两个串A和B,现将B反转,再用插入的形式合成一个串。如:A:abc   B:efg;反转B先,变gfe;作插入,agbfce。现在给出一个串,要求还原出A和B。

思路:扫一遍O(n),串A在扫的时候直接输出,串2在扫的时候反向存储,再输出。

技术分享
 1 #include <iostream>
 2 #include <cmath>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6 const int N=105;
 7 char str[N];
 8 char s2[N];
 9 
10 void cal(int len)
11 {
12     int j=0;
13     for(int i=0,p=len-1; i<len; i+=2)
14     {
15         printf("%c",str[i]);//直接输
16         s2[j++]=str[p];//存起来再输
17         p-=2;
18     }
19     s2[j]=\0;
20     printf("\n%s\n",s2);
21 }
22 
23 int main()
24 {
25     //freopen("input.txt", "r", stdin);
26     int t;
27     cin>>t;
28     while(t--)
29     {
30         scanf("%s",str);
31         cal(strlen(str));
32     }
33     return 0;
34 }
AC代码

 

BestCoder Round #43 pog loves szh I (字符串处理)

原文:http://www.cnblogs.com/xcw0754/p/4559705.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!