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. C#解析JSON数据

    本篇文章主要介绍C#对Json数据的读取. 主要操作过程是: 发送Http请求获取Json数据 把获取的Json数据转换成C#中的类 下面我们以12306火车票余票的数据为例进行切入. 首先来看一下h ...

  2. 搜索打表大找规律 (hdu2045)

    不容易系列之(3)—— LELE的RPG难题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  3. oc语言--description方法和sel

    一.description方法 Description方法包括类方法和对象方法.(NSObject类所包含) (一)基本知识 -description(对象方法) 使用NSLog和@%输出某个对象时, ...

  4. Java Spring MVC

    Spring MVC的实现包括 实现Controller类和基于注解的Controller RequstMapping方式 依赖: <!-- https://mvnrepository.com/ ...

  5. 夏宇闻教授谈FPGA工程师的入门学习

    1. 必须清楚自己究竟适合不适合做工程师. 看看自己的性格特点,是不是特别安静,又耐得住寂寞.因为FPGA工程师是一个辛苦的工作,不但要通过不断学习研究提升自己的设计水平,还要经常性的熬夜加班敲写代码 ...

  6. python多线程同步

    python多线程同步 作者:vpoet 日期:大约在夏季 import threading import time mylock = threading.RLock() num=0 class my ...

  7. 基于spark的plsa实现

    PLSA.py # coding:utf8 from pyspark import SparkContext from pyspark import RDD import numpy as np fr ...

  8. linux添加静态路由表,重启继续生效(转载)

    在日常的使用中,或者在服务器中,有两个网卡配置两个地址,访问不同的网络段,这种情况是非常常见的现象,但是,我们需要额外的添加路由表来决定发送的数据包经过正确的网关和interface才能正确的进行通信 ...

  9. Unsupported Media Type 415问题解决办法(Ajax)

    场景:Ajax传一个json对象到服务器,让参数自动封装至与json对象匹配的java对象中. 错误类型 错误类型1: "status":415 "error" ...

  10. toj2867 Picking Problem

    题目链接:http://acm.tju.edu.cn/toj/showp.php?pid=2867 题目大意:给定一系列活动的开始时间和结束时间,问最多能参加的活动数目 思路:// 本题属于最大区间调 ...