链接:https://ac.nowcoder.com/acm/problem/21488
来源:牛客网
题目描述
被踩在脚下的benTuTuT被迫和jingzhiwang一起去做Fillin找来的一道令人无话可说的题:
有一种字符串的表示方式为桶装康帅傅表示法,他需要你将字符串以’u’型输出。
并且满足如下格式:
1.假设竖着的两条边为a、c,横着的边为b
2.a=c,且a和c在满足a<=b的条件下尽可能大
输入描述:
第一行输入一个整数t,代表有t组测试数据,
对于每组测试数据,输入一个不包含空格的字符串
输出描述:
对于每组测试数据,
按照题目要求输出字符串,
并且每两组测试数据之间应该存在一行空行
示例1
输入
复制
3
swpuacm
hello
helloworld!
输出
复制
s m
w c
pua
h o
ell
h !
e d
l l
lowor
这道题也是简单的C++基础题,没啥可说的,找到字符串长度和U型串左右下的长度关系,问题非常简单就能解决。
AC代码:
#include<iostream>
#include<string>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;cin>>T;
int length,width;
string s,left,right,bottom;
while(T--){
cin>>s;
length=s.length()/3;
if(s.length()%3!=0)length++;
width=(s.length()+2)/3;
if(s.length()%3==2)width++;
else if(s.length()%3==0)width+=2;
left=s.substr(0,length);
bottom=s.substr(length,width-2);
right=s.substr(length+width-2,length);
for(int i=0;i<length;i++){
cout<<left[i];
if(i!=length-1){
for(int j=0;j<width-2;j++)cout<<" ";
}
else{
cout<<bottom;
}
cout<<right[right.length()-i-1]<<endl;
}
cout<<endl;
}
return 0;
}