Q490: Rotating Sentences

Q490: Rotating Sentences

在這個問題中你必須將數列文字往順時針方向旋轉90度。也就是說將原本由左到右,由上到下的句子輸出成由上到下,由右到左。

Input and Output

輸入最多不會超過100列,每列最多不會超過100個字元。

合法的字元包括:換行,空白,所有的標點符號,數字,以及大小寫字母。(注意:Tabs並不算是合法字元。)

最後一列輸入必須垂直輸出在最左邊一行,輸入的第一列必須垂直輸出在最右邊一行。

請參考sample intput/output。

Sample Input

Rene Decartes once said,"I think, therefore I am."

Sample Output

"RIe nteh iDnekc,a rttheesr eofnocree  sIa iadm,. "
//注意:C++结束输入是CTL+Z
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    string str;
    vector<string> v;
    string::size_type max_lenght = 0;
    while(getline(cin,str,'\n'))
    {
        if(max_lenght < str.size()) max_lenght = str.size();
        v.push_back(str);
    }
    for (string::size_type index = 0 ; index < max_lenght ; ++index  )
    {
        for(vector<string>::reverse_iterator It = v.rbegin() ;
            It != v.rend() ; ++It)
            {
                if(index < It->length()) cout<<It->at(index);
                else cout<<' ';
            }
        endl(cout);
    }

    return 0;
}

原文链接: https://www.cnblogs.com/UnGeek/archive/2012/06/03/2532802.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/51809

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午3:22
下一篇 2023年2月9日 上午3:22

相关推荐