`
风吹过PP好冷
  • 浏览: 36650 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

PAT1031 Hello World for U

    博客分类:
  • PAT
阅读更多

Sample Input:

helloworld!

Sample Output:

h   !
e   d
l   l
lowor

 

 

 

 

 

 

 

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
    string str;
    cin>>str;
    int length = str.length();
    int n1 = length/3;
    int n2;
    if (length%3 == 0)
    {
        n1--;
        n2 = n1 + 3;
    }
    else
    {
        n2 = n1 + length%3;
    }
    for (int i = 0; i < n1; i++)
    {
        cout<<str[i];
        for (int j = 0; j < n2 - 2; j++)
        {
            cout<<" ";
        }
        cout<<str[length - 1 -i]<<endl;
    }
    for (int i = length - n1 - n2; i < length - n1; i++)
    {
        cout<<str[i];
    }
    return 0;
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics