日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

17:文字排版

發布時間:2023/12/19 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 17:文字排版 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

17:文字排版

  • 查看
  • 提交
  • 統計
  • 提問
總時間限制:?
1000ms
內存限制:?
65536kB
描述

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

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

輸入
第一行是一個整數n,表示英文短文中單詞的數目. 其后是n個以空格分隔的英文單詞(單詞包括其前后緊鄰的標點符號,且每個單詞長度都不大于40個字母)。
輸出
排版后的多行文本,每行文本字符數最多80個字符,單詞之間以一個空格分隔,每行文本首尾都沒有空格。
樣例輸入
84 One 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 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.


表示linux和windows的編譯環境不一樣,
在dev里格式錯誤但到了noi里滿分,,,,
這就比較尷尬了,,

1 #include<iostream> 2 using namespace std; 3 string kong; 4 string a[1001];//保存每個單詞 5 int tot=1;//行數 6 int main() 7 { 8 int n; 9 cin>>n; 10 for(int i=1;i<=n;i++) 11 { 12 cin>>a[i]; 13 a[i]=a[i]+' '; 14 } 15 string ans; 16 for(int i=1;i<=n;i++) 17 { 18 if((ans.length()+a[i].length()-2)>=80) 19 { 20 if(ans.empty()==true) 21 continue; 22 cout<<ans; 23 cout<<endl; 24 ans=kong; 25 ans=ans+a[i]; 26 tot++; 27 } 28 else 29 { 30 ans=ans+a[i]; 31 } 32 } 33 cout<<ans; 34 return 0; 35 } View Code

?

?

總結

以上是生活随笔為你收集整理的17:文字排版的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。