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); 功能: 分解 ...
随机推荐
- TRIGGERS_监测系统_原始数据表触发器—调用告警信息存储过程
//每次向originaldata表中插入数据就会触发该触发器 create or replace trigger originaldata_to_alarm after insert on ori ...
- [C++程序设计]变量的存储类别
全局变量全部存放在静态存储区中,在程序开始执行时给全局变量分配存储单元,程序执行完毕就释放这些空间.在程序执行过程中它们占据固定的存储单元,而不是动态地进行分配和释放. 在动态存储区中存放以下数据: ...
- asp.net笔记
1. 复习 a) WebForm前后台页面(aspx, aspx.cs)文件在被访问时,会被编译成类,前台类继承于后台类 b) 被访问时,服务器会创建[前台页面类]对 ...
- CSS实现侧边栏固定宽度,内容栏自适应
1,固定宽度区浮动,自适应区不设宽度而设置 margin 我们拿右边定宽左边自适应来做示范,CSS代码如下: #wrap { overflow: hidden; *zoom: 1; } #c ...
- javascript之url转义escape()、encodeURI()和decodeURI()
我们可以知道:escape()除了 ASCII 字母.数字和特定的符号外,对传进来的字符串全部进行转义编码,因此如果想对URL编码,最好不要使用此方法.而encodeURI() 用于编码整个URI,因 ...
- Silverlight 结合ArcGis
原文 http://www.dotblogs.com.tw/justforgood/archive/2012/05/09/72064.aspx 终于有机会谈到ArcGis(觉得很冷门) ,不过既然都做 ...
- C语言的本质(32)——C语言与汇编之C语言内联汇编
用C写程序比直接用汇编写程序更简洁,可读性更好,但效率可能不如汇编程序,因为C程序毕竟要经由编译器生成汇编代码,尽管现代编译器的优化已经做得很好了,但还是不如手写的汇编代码.另外,有些平台相关的指令必 ...
- POJ 2579 Fiber Network(状态压缩+Floyd)
Fiber Network Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3328 Accepted: 1532 Des ...
- canvas.js | CLiPS
canvas.js | CLiPS canvas.js The canvas.js module is a simple and robust JavaScript API for the HTML5 ...
- JNI与JNA性能比较
JNI与JNA性能比较 在介绍JNA时,提到了JNA是基于JNI的,是在JNI上封装了一层,JNI性能不如JNA.最近在网上看到篇简单的比较这两者性能的文档,感觉不错,现转载一下: 分别用JNI和JN ...