浙大pat 1031题解
1031. Hello World for U (20)
Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, "helloworld" can be printed as:
h d
e l
l r
lowo
That is, the characters must be printed in the original order, starting top-down from the left vertical line with n1 characters, then left to right along the bottom line with n2 characters, and finally bottom-up along the vertical line with n3 characters. And more, we would like U to be as squared as possible -- that is, it must be satisfied that n1 = n3 = max { k| k <= n2 for all 3 <= n2 <= N } with n1 + n2 + n3 - 2 = N.
Input Specification:
Each input file contains one test case. Each case contains one string with no less than 5 and no more than 80 characters in a line. The string contains no white space.
Output Specification:
For each test case, print the input string in the shape of U as specified in the description.
Sample Input:
helloworld!
Sample Output:
h !
e d
l l
lowor
#include"iostream"
#include "algorithm"
#include "string"
#include "vector"
using namespace std;
void OutPut(string s)
{
int n = s.size();
int n1,n2;
for(n2=3;n2<=n;n2++)
{
int temp = n+2-n2;
if(temp%2!=0)
continue;
n1 = temp/2;
if(n1<=n2)
break;
}
for(int i=0;i<n1;i++)
{
cout<<s[i];
if(i!=n1-1)
{
for(int t=0;t<n2-2;t++)
cout<<" ";
}
else
{
int k = i+1;
for(int j=0;j<n2-2;++j,++k)
cout<<s[k];
}
cout<<s[n-1-i];
cout<<endl;
}
}
int main()
{
string s;
cin >> s;
OutPut(s);
return 0;
}
浙大pat 1031题解的更多相关文章
- 浙大pat 1035题解
1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...
- 浙大pat 1025题解
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 浙大pat 1011题解
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 浙大PAT 7-06 题解
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 浙大 pat 1003 题解
1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 浙大 pat 1038 题解
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- 浙大 pat 1047题解
1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- 浙大pat 1054 题解
1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...
随机推荐
- Ueditor文件上传问题
我们在做一些网站是会遇到,要有上传文件一类的事情. 我发现百度的富文本编辑器带上传功能,但是没有办法给后台传递我们要的参数. 先在ueditor.all.js中找到, me.execCommand(' ...
- 试制品 (nyoj 542)
模拟 a 反应物集合 ; b 生成物集合; c 存在的化合物或单质集合; ans 新生成化合物集合 1.如果反应无均在已生成的化合物集合中,则完成反应,将合成物加入c集合 2.对每个方程式的反应物进行 ...
- python 算法练习
根据给定的线性函数来确定函数的表达形式: examples: get_function([0,1,2,3,4]) => f(x)=x get_function([1,4,7,10,13]) =& ...
- [安全学习环境]Win7 下DVWA安装指南
一.环境依赖: .Net Framework 3.5 PHP+MySQL 集成测试环境:XAMPP V3.2.1 二.环境准备 1.下载XAMPP(http://www.wampserver.com/ ...
- 【原创】RMQ - ST算法详解
ST算法: ID数组下标: 1 2 3 4 5 6 7 8 9 ID数组元素: 5 7 3 1 4 8 2 9 8 1.ST算法作 ...
- 内存/硬盘/io关系
CPU:工人,干活的,判断以及逻辑处理 硬盘:仓库,原料,数据存储 内存:车间,工人干活的地方,车间中加工原料,当车间中没有原料了,在从仓库中取原料,对原料进行加工 内存本身有一定的存储空间,对内存 ...
- 1.webpack-----模块加载器兼打包工具
一.webpack的优势 1. 能模块化 JS . 2. 开发便捷,能替代部分 grunt/gulp 的工作,比如打包.压缩混淆.图片转base64等. 3. 扩展性强,插件机制完善,特别是支持 Re ...
- 第33届 MPD软件工作坊(南京站)有哪些亮点值得我们参加?
MPD软件工作坊由msup2010年创办,自创办以来,共吸引了万名的软件从业者到场参与.第33届 MPD软件工作坊(南京站)将于12月17-18日在南京召开,大会报名平台:活动家! 快捷报名通道:ht ...
- mouseover和this的巧用
mouseover & mouseout 的问题 在JS中,使用mouseover & mouseout会有触发多次的问题,这里Jquery有了替代的新属性 mouseover == ...
- requests模拟登录
#coding:utf-8 #author:jwong import requests import urllib2 import re from bs4 import BeautifulSoup a ...