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.

输入描写叙述:
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.
输出描写叙述:
For each test case, print the input string in the shape of U as specified in the description.
输入样例:
helloworld!
输出样例:
h   !
e d
l l
lowor
#include <iostream>
#include <cstring>
#include <string> using namespace std; int main()
{
int i1,i2,left_right,down,i,j,k;
char s[1024];
while(cin>>s)
{ i1=(strlen(s)+2)/3;
i2=(strlen(s)+2)%3;
if(1==i2)
{
left_right=i1;
down=i1+1;
}
else if(2==i2)
{
left_right=i1;
down=i1+2;
}
else
{
left_right=down=i1;
}
for(i=0,k=0;i<left_right-1;i++)
{
cout<<s[k];
for(j=2;j<down;j++)
cout<<" ";
cout<<s[strlen(s)-1-k]<<endl;
k++;
}
for(i=k;i<strlen(s)-k;i++)
cout<<s[i];
cout<<endl;
}
return 0;
}

插个图


PAT 1002 Hello World for U (20)的更多相关文章

  1. PAT 1002 写出这个数 (20)(代码)

    1002 写出这个数 (20)(20 分) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10^100 ...

  2. PAT 1002. 写出这个数 (20)

    读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式:在一行内输出n的各位数字之和的每 ...

  3. 【PAT】1002. 写出这个数 (20)

    1002. 写出这个数 (20) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式 ...

  4. PAT乙级 1002. 写出这个数 (20)

    1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...

  5. [C++]PAT乙级1002.写出这个数(20/20)

    /* 1002. 写出这个数 (20) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10^100. ...

  6. PAT 乙级练习题1002. 写出这个数 (20)

    1002. 写出这个数 (20) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式 ...

  7. PAT-乙级-1002. 写出这个数 (20)

    1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...

  8. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  9. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

随机推荐

  1. 用200行Python代码“换脸”

    介绍 本文将介绍如何编写一个只有200行的Python脚本,为两张肖像照上人物的“换脸”. 这个过程可分为四步: 检测面部标记. 旋转.缩放和转换第二张图像,使之与第一张图像相适应. 调整第二张图像的 ...

  2. Android自定义控件实战——水流波动效果的实现WaveView

    转载请声明出处http://blog.csdn.net/zhongkejingwang/article/details/38556891 水流波动的波形都是三角波,曲线是正余弦曲线,但是Android ...

  3. SEO市场是在扩大还是缩小 Seoer终于会变成什么?

    近期有两件全然背道而驰的事情同一时候发生.第一件事情是以SEO业务为主要业务的业者逐渐降低,很多原本是SEO的业者都纷纷转向其它业务.SEO业务反而变成副业.第二件事情是中小企业的SEO需求添加了.而 ...

  4. 【转】 /etc/fstab功能详解

    [转] /etc/fstab功能详解 最近去客户现场时,遇到 了一个关于挂载文件/etc/fstab文件的问题,就写了一下/etc/fstab文件的作用一个文件中各个参数的含义.供大家参考有不正确的地 ...

  5. 机器学习笔记(一)- from Andrew Ng的教学视频

    最近算是一段空闲期,不想荒废,记得之前有收藏一个机器学习的链接Andrew Ng的网易公开课,其中的overfiting部分做组会报告时涉及到了,这几天有时间决定把这部课程学完,好歹算是有个粗浅的认识 ...

  6. Android面试题整理(1)

    1.Activity的生命周期      onCreate(Bundle saveInstanceState):创建activity时调用.      onStart():activity可见时调用 ...

  7. __get __set 实例

    <?php class Person { //下面是人的成员属性,都是封装的私有成员 private $name; //人的名子 private $sex; //人的性别 private $ag ...

  8. 面向对象程序设计-C++ Default constructor & Copy constructor& Destructor & Operator Overloading【第九次上课笔记】

    先上笔记内容吧: 这次上课的内容有关 构造函数 析构函数 运算符重载 return * this 内容很细,大家好好回顾笔记再照应程序复习吧 :) #include <iostream> ...

  9. Chapter 17 Replication 复制

    Chapter 17 Replication 复制 Table of Contents 17.1 Replication Configuration 17.2 Replication Implemen ...

  10. CString——Left、Right、Find、ReverseFind

    CString--Left.Right.Find.ReverseFind http://hi.baidu.com/shawmar/item/08b30afb0f32d46f3c1485ec CStri ...