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. MySQL PrepareStatement基本的两种模式&客户端空间占用的源码分析

    关于预编译(PrepareStatement),对于所有的JDBC驱动程序来讲,有一个共同的功能,就是“防止SQL注入”,类似Oracle还有一种“软解析”的概念,它非常适合应用于OLTP类型的系统中 ...

  2. ShareSDK for Android 只有新浪微博分享

    本文代码例子:http://pan.baidu.com/share/link?shareid=3710053477&uk=3189484501 ShareSDK 官方的例子非常好,但代码太多看 ...

  3. Cocoapods安装步骤

    Cocoapods安装步骤 1.升级Ruby环境 终端输⼊入:$ gem update --system 此时会出现 ERROR: While executing gem ... (Gem::File ...

  4. 字符串查找函数 find()函数

    find()函数可以帮助你在两个字符串之间,查找很多他们的关系... #include<iostream> #include<string> using namespace s ...

  5. vs2010如何打开vs2013

    vs2010如何打开vs2013 百度经验有,简单实用.

  6. pyfits过滤数据更新文件。

    import pyfits as pf import numpy as np import matplotlib.pyplot as plt hdulist = pf.open("LE_ev ...

  7. eclipse+tomcat+maven debug的时候总是出现source not found /Edit lookup path...的问题解决方案

    eclipse+tomcat+maven debug的时候总是出现source not found /Edit  lookup path...的问题解决方案 这个问题纠结好久好久.... 问题出现的环 ...

  8. 最新的QT git代码到code.qt.io/cgit,还有planet.qt.io有许多博客

    http://code.qt.io/cgit/ http://planet.qt.io/

  9. HttpComponents 也就是以前的httpclient项目

    HttpComponents 也就是以前的httpclient项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端/服务器编程工具包,并且它支持 HTTP 协议最新的版本和建议.不 ...

  10. android 从服务器上获取APK并下载安装

    简单的为新手做个分享.    网上有些资料,不过都是很零散,或是很乱的,有的人说看不懂.    一直有新手说 做到服务器更新APK时没有思路,这里做个简单的分享,希望有不同思路的可以讨论.     下 ...