题解 | Hello World for U

Hello World for U

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

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
    string str;
    while(cin >> str){
        int len = str.size();
        double k = (double)(len - 2) / (double)(3);
        int num;
        if(k - floor(k) >= 0.5){
            num = ceil(k);
        }else{
            num = floor(k);
        }        //确定从第几个字母折叠
        for(int i = 0; i < num; i ++){
            cout << str[i];
            for(int j = 0; j < len - 2 - 2 * num; j++){
                cout << " ";
            }
            cout << str[len - i -1] << endl;
        }
        for(int i = 0; i < len - 2 * num; i++){
            cout << str[num + i];
        }
        cout << endl;
    }

    return 0;
}

全部评论

相关推荐

人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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