摘要
题目链接 |
难度等级 |
完成状态 |
完成分数 |
最后编辑时间 |
需要注意
|
文字排版
|
★☆☆☆☆
|
答案正确
|
100
|
2014/12/18 23:13:00
|
无
|
题意
文字按照每行80字符重排。
题解
- getline读入一整行然后用sstream分词,详见之前的文(右上角分别搜索getline和sstring)。
- 另一种方法似乎更加简洁,这么写就好,具体代码懒得写了,string库详见之前的文(右上角搜索string库):
- s.substr(0,s.rfind(" ",80));
详细的这儿就不赘述了。顺手帮同学写的,居然调快半个小时,原因是把sstream的输出当成自动空格的了,我一定是蠢了。
代码
sd3.cpp代码已折叠
展开折叠内容
|
- #include<cstdio>
- #include<cstdlib>
- #include<iostream>
- #include<sstream>
- using namespace std;
- string s,line,a;
- stringstream ste;
- int main()
- {
- int n;
- cin>>n;
- getline(cin,s,'\n');
- while(getline(cin,s,'\n'))
- {
- if(s.size()==0)
- break;
- line="";
- ste<<s;
- while(ste>>a)
- {
- if(line=="")
- line=a;
- else if(line.size()+a.size()<80)
- line+=" "+a;
- else
- {
- cout<<line<<endl;
- line=a;
- }
- }
- cout<<line<<endl;
- line="";
- }
- return 0;
- }
|