1031 Hello World for U (20 分)
 

Given any string of N (≥) 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 n​1​​ characters, then left to right along the bottom line with n​2​​ characters, and finally bottom-up along the vertical line with n​3​​ characters. And more, we would like U to be as squared as possible -- that is, it must be satisfied that n​1​​=n​3​​=max { k | k≤n​2​​ for all 3 } with n​1​​+n​2​​+n​3​​−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

题意

一开始没看懂题意,看懂以后一遍过。

尽可能围成正方形。在满足n1=n3,且n1<=n2的条件下,n1尽可能地大。

底部字符数量 n2 最少为3。n1 = n3 要尽量等于 n2 。也就是说,n1 = n3 = (n+2) / 3;因为 '/ 3' 会截掉小数部分,所以 n1 和 n3 总是小于或者等于 n2 。

AC代码:

#include<bits/stdc++.h>
using namespace std;
char a[];
int main(){
cin>>a;
int l=strlen(a);
int n1=(l+)/;
int n2=l-n1*;
//cout<<n1<<" "<<n2<<endl;
for(int i=;i<n1-;i++){
cout<<a[i];
for(int j=;j<=n2;j++){
cout<<" ";
}
cout<<a[l--i]<<endl;
}
for(int i=n1-;i<=n1+n2;i++){
cout<<a[i];
}
return ;
}

PAT 甲级 1031 Hello World for U (20 分)(一开始没看懂题意)的更多相关文章

  1. PAT甲级:1136 A Delayed Palindrome (20分)

    PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...

  2. PAT 甲级 1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  3. PAT 甲级 1027 Colors in Mars (20 分)

    1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...

  4. PAT 甲级 1005 Spell It Right (20 分)

    1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...

  5. PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)

    1058 A+B in Hogwarts (20 分)   If you are a fan of Harry Potter, you would know the world of magic ha ...

  6. PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  7. PAT Advanced 1031 Hello World for U (20 分)

    Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For ...

  8. 【PAT甲级】1054 The Dominant Color (20 分)

    题意: 输入两个正整数M和N(M<=800,N<=600),分别代表一张图片的宽度和高度,接着输入N行每行包括M个点的颜色编号,输出这张图片主导色的编号.(一张图片的主导色占据了一半以上的 ...

  9. 【PAT甲级】1001 A+B Format (20 分)

    题意:给两个整数a,b,计算a+b的值并每三位用逗号隔开输出(−1e6​​≤a,b≤1e6​​) AAAAAccepted code: #include<bits/stdc++.h> us ...

随机推荐

  1. 遍历SQL SERVER中所有存储过程和触发器

    如果需要查找某个存储过程或触发器中是否含有某段文本(比如:你想知道有哪些存储过程操作了某个表) 可以这么写 select name from sysobjects o, syscomments s w ...

  2. .NET Core SignalR 和 .NET SignalR 区别

    由于要转 .NET Core ,对于以前用到的一些进行迁移. 在迁移 SignalR 的时候发现 .NET Core 下的和 .NET 下的区别还是挺大的. 功能差异 自定重新连接 .NET 下的 S ...

  3. LoadRunner在Controller场景中配置获取Windows Resources

    一.首先需要在被监控Windows服务器端(只支持Windows)进行如下设置: 启动服务: Remote Procedure Call (RPC) RemoteRegistry 操作方法: 按Win ...

  4. sql server 存储过程 output 和return的使用 方法,详解

    SQL Server目前正日益成为WindowNT操作系统上面最为重要的一种数据库管理系统,随着 SQL Server2000的推出,微软的这种数据库服务系统真正地实现了在WindowsNT/2000 ...

  5. Linux 理解 %iowait (%wio)

    理解 %iowait (%wio) 2016/02/25 %iowait 是 “sar -u” 等工具检查CPU使用率时显示的一个指标,在Linux上显示为 %iowait,在有的Unix版本上显示为 ...

  6. 013_Python3 条件控制

    1.if #!/usr/bin/python3   var1 = 100 if var1:     print ("1 - if 表达式条件为 true")     print ( ...

  7. 001_git: 版本控制软件

    一.基础配置 1.安装]# yum install -y git 2.配置用户信息配置用户联系方式:名字.email]# git config --global user.name "Mr. ...

  8. CF938D Buy a Ticket dijkstra

    考试T1,建一个反图跑一个最短路就好了~ code: #include <bits/stdc++.h> #define ll long long #define N 200002 #def ...

  9. zabbix数据的时序-

    gj的proxy服务器经过重启之后时序有变化. zabbix数据库中数据的存储是以哪方为准server端还是agent端, 触发事件跟恢复时间反了,本应该恢复的事件在数据库中查询event,得到的事件 ...

  10. loj #136

    最小瓶颈路 做最小生成树是进行特判即可 时间复杂度 n * k #include <bits/stdc++.h> const int N = 1010, M = 1e5 + 10; str ...