2005-11-21 01:46
第三题
1
1个1,11
2个1,21
1个2,1个1,1211
1个1,1个2,2个1,111221
下一行应该是
3个1,2个2,1个1 312211
1
1个1,11
2个1,21
1个2,1个1,1211
1个1,1个2,2个1,111221
下一行应该是
3个1,2个2,1个1 312211
代码:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
main()
{
string s = "1";
cout << s << endl;
for( int N=0; N<10; ++N )
{
ostringstream os;
for( size_t i=0; i<s.length(); ++i )
{
size_t n = 1;
char c = s[i];
for( ; i<s.length() && s[i+1]==c; ++i ) ++n;
os << n << c;
}
s = os.str();
cout << s << endl;
}
return 0;
}
请小心你的思想,它会影响你的行为,
请小心你的行为,它会影响你的习惯,
请小心你的习惯,它会影响你的性格,
请小心你的性格,它会影响你的命运。
请小心你的行为,它会影响你的习惯,
请小心你的习惯,它会影响你的性格,
请小心你的性格,它会影响你的命运。