题解 | #Hello World for U#

Hello World for U

https://www.nowcoder.com/practice/c6e414fddd7c401887c350c9cc41f01b

#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <climits>
#include <iostream>
#include <algorithm>
#include <bitset>
using namespace std;

int main(){
    string str1;
    int length;
    int max;
    while(cin>>str1){
        string result="                           ";
        length=str1.size();
        for (int i = 0; i < length-2*i; ++i) {
            max=i;
        }
        //max代表n1 n3长度 不包括底部的那一个字符
        for (int i = 0,j=length-1; i<max; ++i,--j) {
            result=result.substr(0,length-2*max-2);
            printf("%c%s%c\n",str1[i],result.c_str(),str1[j]);
        }
        //打印最后一行
        printf("%s\n",str1.substr(max,length-2*max).c_str());
    }
}
全部评论

相关推荐

05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务