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 }
?
?