To and Fro

点我

Problem Description
Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array of letters. For example, if the message is “There’s no place like home on a snowy night” and there are five columns, Mo would write down

t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e
m o t
n l e w x

Note that Mo includes only letters and writes them
all in lower case. In this example, Mo used the character ‘x’ to pad the message
out to make a rectangle, although he could have used any letter.

Mo then
sends the message to Larry by writing the letters in each row, alternating
left-to-right and right-to-left. So, the above would be encrypted
as

toioynnkpheleaigshareconhtomesnlewx

Your job is to recover for
Larry the original message (along with any extra padding letters) from the
encrypted one.

 
Input
There will be multiple input sets. Input for each set
will consist of two lines. The first line will contain an integer in the range
2. . . 20 indicating the number of columns used. The next line is a string of up
to 200 lower case letters. The last input set is followed by a line containing a
single 0, indicating end of input.
 
Output
Each input set should generate one line of output,
giving the original plaintext message, with no spaces.
 
Sample Input
5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
 
Sample Output
theresnoplacelikehomeonasnowynightx
thisistheeasyoneab
 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int i,n;
char ch;
char a[][];
char b[];
bool flag=;
int p=,j=;
while(cin>>n&&n)
{
int k=;
memset(b,,sizeof(b));
memset(a,,sizeof(a));
getchar();
gets(b);
int len=strlen(b);
while(k<=len)
{
if(!flag)
{
for(i=;i<n;i++)
if(k<=len)
a[p][i]=b[k++];
flag=;
p++;
continue; }
if(flag)
{
for(i=n-;i>=;i--)
if(k<=len)
a[p][i]=b[k++];
flag=;
p++;
continue;
}
}
for(i=;i<n;i++)
{
for(j=;j<p-;j++)
{
printf("%c",a[j][i]);
}
}
cout<<endl;
p=;
}
}
 #include <stdio.h>
#include <string.h>
int main()
{
char c,s[][];
int i,j,k,n,f,count;
while(scanf("%d",&n),n){
f=count=;
for(k=;f==;k++)
for(i=;i<=n&&f==;i++){
scanf("%c",&c);
if(c=='\n') f=;
else{
count++;
if(k%==) s[k][i]=c;
else s[k][n-i+]=c;
}
}
for(i=;i<=n;i++)
for(j=;j<=count/n;j++)
putchar(s[j][i]);
putchar('\n');
}
return ;
}

To and Fro(字符串水题)的更多相关文章

  1. 1222: FJ的字符串 [水题]

    1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1  =  “A” A2  =   ...

  2. 1001 字符串“水”题(二进制,map,哈希)

    1001: 字符串“水”题 时间限制: 1 Sec  内存限制: 128 MB提交: 210  解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...

  3. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  4. HDU ACM 1073 Online Judge -&gt;字符串水题

    分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...

  5. HDU4891_The Great Pan_字符串水题

    2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=48 ...

  6. Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题

    B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...

  7. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题

    A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  8. uva 10252 - Common Permutation 字符串水题

    题意:給定兩個小寫的字串a與b,請印出皆出現在兩字串中的字母,出現的字母由a~z的順序印出,若同字母出現不只一次,請重複印出但不能超過任一字串中出現的次數.(from Ruby兔) 很水,直接比较输出 ...

  9. hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用

    字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...

随机推荐

  1. HTML5简单入门系列(二)

    前言 上篇中写到HTML5中的画布(canvas)元素,查看了canvas其他的资料,发现这个元素相关内容太多,鉴于本系列只是基础(主要是LZ也是初学),不再做太多介绍,有机会的话再单独写相关内容.说 ...

  2. 为采集动态网页安装和测试Python Selenium库

    1. 引言上一篇<为编写网络爬虫程序安装Python3.5>中测试小例子对静态网页做了一个简单的采集程序,而动态网页因为需要动态加载js获取数据,所以使用urllib直接openurl已经 ...

  3. Azure上A/D系列虚拟机到DS系列迁移(2)

    11. 该脚本会检测环境,停止虚拟机,拷贝VHD文件,创建磁盘等等,知道出现如下类似画面,他会暂停等待用户操作: 后面这几个步骤非常重要,关系到你后续的创建是否成功: 12. 进入D:\migvm目录 ...

  4. OpenCV图片类cv::Mat和QImage之间进行转换(好多相关文章)

    在使用Qt和OpenCV混合编程时,我们有时需要在两种图片类cv::Mat和QImage之间进行转换,下面的代码参考了网上这个帖子: //##### cv::Mat ---> QImage ## ...

  5. 有意思的GacUI

    所有方法,无论是你写还是工具来codegen还是用宏,最终都指向把这些名字和对应的指针存在一个map里.C++是不提供这个功能的,我也没仔细研究过qt怎么做,不过我在我自己的gacui里面实现了类似的 ...

  6. SQLSERVER读懂语句运行的统计信息

    SQLSERVER读懂语句运行的统计信息 对于语句的运行,除了执行计划本身,还有一些其他因素要考虑,例如语句的编译时间.执行时间.做了多少次磁盘读等. 如果DBA能够把问题语句单独测试运行,可以在运行 ...

  7. 正则取页面图片URL和TABLE BackGround

    /// <summary> /// 根据html文本返回url地址集合 /// </summary> /// <param name="sHtmlText&qu ...

  8. 将Oracle JDBC驱动库安装到本地仓库

    1.为了添加详细版本信息,先查看当前Oracle数据库版本 select * from v$version; 查询返回如下信息 BANNER ----------------------------- ...

  9. 剑指offer-面试题16.反转链表

    题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反转后的头结点 链表结点定义如下: struct ListNode { int m_nKey; ListNode* m_pNext; } 其实 ...

  10. Android学习总结——Service组件

    从Service的启动方式上,可以将Service分为Started Service和Bound Service.在使用Service时,要想系统能够找到此自定义Service,无论哪种类型,都需要在 ...