题解 | #Hello World for U#

Hello World for U

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

#include<iostream>
#include<cstdio>

using namespace std;
int main() {
    char str[81];
    while (scanf("%s", &str) != EOF) {
        char matrix[80][80];
        for (int i = 0; i < 80; ++i) {
            for (int j = 0; j < 80; ++j) {
                matrix[i][j] = ' ';
            }
        }
        int count = 0;
        while (str[count] != '\0') {
            ++count;
        }
        int x, y;    
        x = (count + 2) / 3;
        y = x + (count + 2) % 3;
        for (int i = 0; i <= y - 1; ++i) {
            matrix[x - 1][i] = str[x - 1 + i];
        }
        for (int j = 0; j <= x - 1; ++j) {
            matrix[j][0] = str[j];
            matrix[j][y - 1] = str[count - 1 - j];
        }
        for (int i = 0; i <= x - 1; ++i) {
            for (int j = 0; j <= y - 1; ++j) {
                cout << matrix[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}
全部评论

相关推荐

牛牛不会牛泪:脉脉太多这种了,纯水军
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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