1.13.17

來源:互聯網
上載者:User

標籤:整數   std   之間   strlen   include   ems   children   str   文本   

17:文字排版

描述

給一段英文短文,單詞之間以空格分隔(每個單詞包括其前後緊鄰的標點符號)。請將短文重新排版,要求如下:

每行不超過80個字元;每個單詞居於同一行上;在同一行的單詞之間以一個空格分隔;行首和行尾都沒有空格。

輸入第一行是一個整數n,表示英文短文中單詞的數目. 其後是n個以空格分隔的英文單詞(單詞包括其前後緊鄰的標點符號,且每個單詞長度都不大於40個字母)。輸出排版後的多行文本,每行文本字元數最多80個字元,單詞之間以一個空格分隔,每行文本首尾都沒有空格。範例輸入

84One sweltering day, I was scooping ice cream into cones and told my four children they could "buy" a cone from me for a hug. Almost immediately, the kids lined up to make their purchases. The three youngest each gave me a quick hug, grabbed their cones and raced back outside. But when my teenage son at the end of the line finally got his turn to "buy" his ice cream, he gave me two hugs. "Keep the changes," he said with a smile. 

範例輸出

One sweltering day, I was scooping ice cream into cones and told my fourchildren they could "buy" a cone from me for a hug. Almost immediately, the kidslined up to make their purchases. The three youngest each gave me a quick hug,grabbed their cones and raced back outside. But when my teenage son at the endof the line finally got his turn to "buy" his ice cream, he gave me two hugs."Keep the changes," he said with a smile.
 1 #include <cstdio> 2 #include <cstring> 3 using namespace std; 4 char m[50]; 5 int n,tot,x; 6 int main() 7 { 8     scanf("%d",&n); 9     while(++x<=n)10     {11         scanf("%s",m);12         tot+=strlen(m);13         if(tot!=80) tot++;14         if(tot>80)15         {16             printf("\n");17             tot=strlen(m)+1;18         }19         printf("%s",m);20         if(tot!=80&&x!=n) printf(" ");21         memset(m,0,sizeof(m));22     }23     return 0;24 }

 

1.13.17

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.