To and Fro(字符串水题)
To and Fro
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.
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.
giving the original plaintext message, with no spaces.
#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(字符串水题)的更多相关文章
- 1222: FJ的字符串 [水题]
1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = ...
- 1001 字符串“水”题(二进制,map,哈希)
1001: 字符串“水”题 时间限制: 1 Sec 内存限制: 128 MB提交: 210 解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
- HDU4891_The Great Pan_字符串水题
2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=48 ...
- 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 ...
- 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 ...
- uva 10252 - Common Permutation 字符串水题
题意:給定兩個小寫的字串a與b,請印出皆出現在兩字串中的字母,出現的字母由a~z的順序印出,若同字母出現不只一次,請重複印出但不能超過任一字串中出現的次數.(from Ruby兔) 很水,直接比较输出 ...
- hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用
字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...
随机推荐
- 轻松实现HTML5时钟(分享下自己对canvas的理解,原来没你想像的那么难哦)
Hey,guys! 让我们一起用HTML5实现一下简易时钟吧! 接触canvas时, 我突然有一种非常熟悉的感觉------canvas的部分的功能其实和Photoshop中的 钢笔工具 是一样的.所 ...
- export-data.js
var timeBtnClick = (function() { function _todayClick() { $('.select-time .today').on('click', funct ...
- Django auth 登陆后页面跳转至/account/profile,修改跳转至其他页面
这几天在学习django,django功能很强大,自带的auth,基本可以满足用户注册登陆登出,简单的用户注册登陆系统使用django auth足矣.当然也不是拿来就能用的,需要自己写登陆页面的模板, ...
- SPOJDIVCNT2: Counting Divisors(莫比乌斯反演)
http://acm.tzc.edu.cn/acmhome/vProblemList.do?method=problemdetail&oj=SPOJ&pid=DIVCNT2 给出n求 ...
- cf478D Red-Green Towers
D. Red-Green Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- PhpEclipse插件
PHP开发工具 PHPEclipse PHPEclipse 是一个相当强大的一个Eclipse下开发PHP的插件,包括的功能有:PHP语法分析,调试,代码格式化,大纲视图,代码模板定制等. 安装地址: ...
- 使用Canvas实现动画效果 | DKlogs -- 设计 | 生活
使用Canvas实现动画效果 | DKlogs -- 设计 | 生活 使用Canvas实现动画效果
- 自定义View的编写
在项目的时候,很多情况要用到自定义View来达到自己想要的效果,所有自定义View的编写很重要. 首先看看所要实现的效果: 最上面的一行字“LogicView”每次从左向右滚动,下面的圆从角度0到36 ...
- SPOJ 130 - Rent your airplane and make money(dp+优化)
题意:有n列预定航班,从st时刻开始出发,飞行时间为d,花费为p,且同一时刻不能有两个航班,求最大的花费 对航班的开始时间(或结束时间)按升序排序,从后往前找到对应结束时间所在的航班位置(如按结束时间 ...
- 虚拟化之KVM的安装篇
1,在安装KVM之前,首先需要在自己的电脑开启cpu虚拟化技术(这个需要BIOS中设置). 如下操作都是在本人虚拟机中设置,所以可以看到我多添加一块磁盘,目的是用来做kvm虚拟机的磁盘. 另外,虚拟机 ...