1031. Hello World for U (20)

来源:互联网 发布:js自定义全局函数 编辑:程序博客网 时间:2024/06/05 15:03

一道水题,求出n1,n2,n3的值,然后按格式输出就好:n1行
前n1-1行都是,s[t]+n2-2个空格+s[s.size()-t-1]
最后一行是s[n1-1 … n1+n2-2]

#include<iostream>#include<string>using namespace std;int main(){    string s;    cin >> s;    int N = s.size();    int n1 = (N + 2) / 3;    int n2 = N + 2 - 2 * n1;    string str(n2 - 2, ' ');    string str2(s.begin() + n1 - 1, s.begin()+n1+n2-1);//s.end()是最后一个的下个迭代器    for (int t = 0;t < n1;t++)    {        if (t != n1 - 1)            cout << s[t] << str << s[s.size() - 1 - t] << endl;        else            cout << str2<<endl;    }};
0 0
原创粉丝点击