http://acm.zju.edu.cn/show_problem.php?pid=1099
刚开始写VC++.
我是小搓人一个,下面是Steve GG的代码;主要是细心,方方面面都要考虑全面了。
if ( colCount + length > 80 ) {
cout << endl;
colCount = 0;
}
cout << text;
colCount += length;
}
这段代码为啥列出来,我到现在还没明白,有高手的指点一下啊。
#include "iostream"
#include "string"
using namespace std;
int main( void ) {
string text;
int colCount = 0;
while ( cin >> text ) {
if ( text == "<br>" ) {
cout << endl;
colCount = 0;
} else if ( text == "hr" ) {
if ( colCount > 0 ) {
cout << endl;
}
cout << "----------------------------------------"
<< "----------------------------------------"
<< endl;
colCount = 0;
} else {
int length = text.length( );
if ( colCount > 0 ) {
if ( colCount + length > 79 ) {
cout << endl;
colCount = 0;
} else {
cout << " ";
++colCount;
}
cout << text;
colCount += length;
} else {
if ( colCount + length > 80 ) {
cout << endl;
colCount = 0;
}
cout << text;
colCount += length;
}
}
}
cout << endl;
return 0;
}
文章评论(0条评论)
登录后参与讨论