浙大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 ...
随机推荐
- xtrabackup在线备份及还原
xtrabackup下载https://www.percona.com/downloads/XtraBackup/LATEST/xtrabackup文档https://www.percona.com/ ...
- Windows离开模式(AwayMode)
Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Man ...
- oc内容5大区
1.堆区(malloc):不需要手动管理内存,自动管理 2.栈区(stack):需要手动管理内存 3.静态区 4.常量区 5.方法区 load类方法:把类加载进内存的时候调用,只会调用一次 initi ...
- jQuery事件命名空间
先看一些代码: 也可以用bind进行事件绑定.我们看到上面的代码,我们可以在事件后面,以点号,加我们的名字,就是事件命名空间.所谓事件命名空间,就是事件类型后面以点语法附加一个别名,以便引用事件,如& ...
- hdu 5997 rausen loves cakes(线段数合并+启发式修改)
题目链接:hdu 5997 rausen loves cakes 题意: 给你n个点,每个点有一个颜色,现在有两个操作,第一个操作,将颜色x改为颜色y,第二个操作,询问[x,y]区间有多少颜色段(颜色 ...
- sql 时间格式化
sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...
- TypeScript -- 面向对象特性
.class关键字和类名就可以定义一个类 . 类的访问控制符--有三个,.] = ] = ] = ;.声明参数 .用接口声明方法 .理解模块--一个文件就是一个模块,就是这么个意思 ,不用想的多么高大 ...
- Hive插数据报错
报错信息: Failed with exception MetaException(message:javax.jdo.JDODataStoreException: Put request faile ...
- AxonVR:体验有触觉有温度的VR世界
提到VR,通常指的是 Oculus Rift 及 HTC Vive的头盔:它们以视觉及听觉使你感到身处虚拟世界.头盔成功的在视觉及听觉感官上蒙骗了你,但我们体验现实的感官不仅于此.绝大多数的VR产品忽 ...
- 敏捷开发(八)- Scrum Sprint计划会议1
本文主要是为了检测你对SCRUM Sprint 计划会议的了解和使用程度, 通过本文你可以检测一下 1.你们的SCRUM Sprint 计划会议的过程和步骤 2.会议的输出结果 S ...