YTU 2898: C-Z型变换
2898: C-Z型变换
时间限制: 1 Sec 内存限制: 128 MB
提交: 53 解决: 15
题目描述
输入
输出
样例输入
PAYPALISHIRING 3
样例输出
PAHNAPLSIIGYIR
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <iostream>
using namespace std;
int main()
{
char s[100];
char out[100];
int n,i,len,j,temp,temp1,temp2,count;
while(cin>>s,cin>>n)
{
count=0;
len=0;
temp=2*(n-1);
while(s[len++]!=NULL);
len--;
if(n==1)cout<<s;
else
{
for(i=0; i<n; i++)
{
if(i==0||i==n-1)
{
out[count++]=s[i];
for(j=temp; i+j<len; j+=temp)
out[count++]=s[i+j];
}
else
{
out[count++]=s[i];
temp1=temp-2*i;
temp2=2*i;
if(temp1==temp2)
{
for(j=temp1; i+j<len; j+=temp1)
out[count++]=s[i+j];
}
else
{
for(j=temp1; i+j<len; j+=temp)
{
out[count++]=s[i+j];
if(i+j+temp2<len)
out[count++]=s[i+j+temp2];
}
}
}
}
for(i=0; i<len; i++)
cout<<out[i];
}
cout<<'\n';
}
return 0;
}
YTU 2898: C-Z型变换的更多相关文章
- Z 字形变换 C++实现 java实现 leetcode系列(六)
Z 字形变换 java实现 C++实现 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 ...
- C#版[击败100.00%的提交] - Leetcode 6. Z字形变换 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- Leetcode题库——6.Z字形变换
@author: ZZQ @software: PyCharm @file: convert.py @time: 2018/9/20 20:12 要求: Z字形变换 将字符串 "PAYPAL ...
- LeetCode Golang 6. Z 字形变换
6. Z 字形变换 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L ...
- Leetcode(6)Z字形变换
Leetcode(6)Z字形变换 [题目表述]: 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" ...
- Java实现 LeetCode 6 Z字形变换
6. Z 字形变换 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L ...
- [LeetCode] Z字型变换
题目内容: 将字符串 "PAYPALISHIRING" 以Z字形排列成给定的行数: P A H N A P L S I I G Y I R 之后从左往右,逐行读取字符:" ...
- leetcode 6 z字型变换
执行用时 :64 ms, 在所有 Python3 提交中击败了99.74%的用户由题目可知 我们的最终字符串会被摆成 numRows 行,那我们理解为 最终结果是numRows个字符串相加 先建立等于 ...
- leetcode 6/300 Z字型变换 py
目录 题目说明 方法一:利用flag 题目说明 方法一:利用flag 简单来说就是利用flag来表示方向,真的神来之笔. class Solution: def convert(self, s: st ...
随机推荐
- 循环中i++和++i哪个好
推荐使用++i,因为不需要返回临时对象,执行效率更高.
- 零基础入门学习Python(2)--用Python设计第一个游戏
前言 小甲鱼的Python课程都是围绕着一个个小游戏,进行Python的讲解,由易入难. 小游戏流程图 Created with Raphaël 2.1.2Startprint('---------- ...
- PHPExcel读取表格内容
PHPExcel读取表格 先引入类IOFactory.php require_once '../PHPExcel/IOFactory.php'; $filePath = "test.xlsx ...
- 【ZOJ - 3780】 Paint the Grid Again (拓扑排序)
Leo has a grid with N × N cells. He wants to paint each cell with a specific color (either black or ...
- HTML文件中css样式的引用
1.1.直接在div中使用css样式制作div+css网页 如: <div style="font-size:14px; color:#FF0000;">内容</ ...
- [K/3Cloud] 调用其他界面时通过Session传递对象参数
DynamicFormShowParameter参数的CustomParams参数列表只支持string类型的参数,对于复杂参数的传递需要通过单据View对象的共享Session来完成,如: 在调用界 ...
- 【electron系列之一】创建右下角通知栏小图标
electron 用Tray对象来实现右下角通知栏小图标 一.先引入app, BrowserWindow来实现浏览器功能,接着引入Tray, Menu来实现右下角 二. new Tray('./pag ...
- [bzoj3252]攻略_dfs序_线段树_贪心
攻略 bzoj-3252 题目大意:给定一棵n个节点的有根树,点有点权.让你选出至多k个节点,使得他们到根的链的并最大. 注释:$1\le n\le 2\cdot 10^5$,$1\le val_i\ ...
- 更新数据库中数据时出现: Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences 问题
使用workbench在数据库中更新数据时报错: You are using safe update mode and you tried to update a table without a WH ...
- windows安装docker
主要參考:http://docs.docker.com/installation/windows/ [1]安装完毕后同意后可能会报错: error in run: Failed to start ma ...