PAT 1002 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.
输入描写叙述:
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)的更多相关文章
- PAT 1002 写出这个数 (20)(代码)
1002 写出这个数 (20)(20 分) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10^100 ...
- PAT 1002. 写出这个数 (20)
读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式:在一行内输出n的各位数字之和的每 ...
- 【PAT】1002. 写出这个数 (20)
1002. 写出这个数 (20) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式 ...
- PAT乙级 1002. 写出这个数 (20)
1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...
- [C++]PAT乙级1002.写出这个数(20/20)
/* 1002. 写出这个数 (20) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10^100. ...
- PAT 乙级练习题1002. 写出这个数 (20)
1002. 写出这个数 (20) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式 ...
- PAT-乙级-1002. 写出这个数 (20)
1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...
- PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642
PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...
- PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
随机推荐
- chr()、unichr()和ord(),全半角转换,ValueError: unichr() arg not in range() (wide Python build)
chr().unichr()和ord() chr()函数用一个范围在range(256)内的(就是0-255)整数作参数,返回一个对应的字符. unichr()跟它一样,只不过返回的是 Unicode ...
- 深入浅出 JSTL
JSLT标签库,是日常开发经常使用的,也是众多标签中性能最好的.这个算是一个java程序员的一个基本功吧. JSP Standard Tag Library (JSTL) 的规范完成于2002年7月, ...
- 你会用swift创建复杂的加载动画吗(1)
时至今日,iOS 应用商店已经拥有超过了140万 应用,让你自己的应用脱颖而出确实是个不小的挑战.不过,在你的应用掉入默默无闻的大黑洞之前,你拥有一个小小的机遇窗,它能帮你吸引用户的注意. AD: 时 ...
- iOS之UITableViewCell左右滑动效果
首先在 UITableViewCell.h 中声明一个代理 @protocol UITableViewCellSlideDelegate <UITableViewDelegate> @op ...
- 在CTime类中重载<<和>>
程序代码: #include <iostream> using namespace std; class CTime//时间类 { private: unsigned short int ...
- 如何成为CSDN博客专家
先看一下官方给出的要求: 申请CSDN博客专家应具备的条件: 1.原创IT类文章总数超过20篇,并且最近一个月内发布了新的原创IT类文章. 2.博客文章总的浏览量超过5万次以上. 3.文章内容的质量很 ...
- 转化为用欧几里得算法判断互质的问题D - Wolf and Rabbit
Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...
- gpexpand error:Do not have enough valid segments to start the array.
gpstart error: Do not have enough valid segments to start the array. 这个时候需要检查一下shared_buffers设置改小点,就 ...
- php 学习笔记 数组2
10.切割数组 array_slice(array, offset, length);返回一个由原始数组中的连续元素组成的新数组,参数1为原始数组,参数2为要复制的起始位置, 参数3要复制的个数:新数 ...
- 版本管理神器git上手
由于以前折腾过svn,虽然最终没有用成功,但是也算有经验,git入门还是比较简单的. 在新目录下建立初始化版本库 : git init git add file git add file2 git ...