题目如下:
1
11
21
1211
111221
….这行字是什么?

解答:仔细琢磨琢磨其实已经发现了
1 1
11一个一
21二个一
1211一个二一个一
111221一个一一个二二个一
312211三个一二个二一个一
13112221一个三一个一二个二一个一

附C++版的算法
[code=cpp]#include
#include
#include
using namespace std;

int main( void )
{
string s = "1";
cout << s << endl;
for( int N=0; N<10; ++N ) //N是计算的个数,100的时候我电脑就吃不住了
{
ostringstream os;
for( size_t i=0; i{
size_t n = 1;
char c = s[i];
for( ; ios << n << c;
}
s = os.str();
cout << s << endl;
}
return 0;
} [/code]
程序运行结果如图:

  One Response to “简单的逻辑推理—-详解”

  1. 是不是打开c++程序,建立exe程序,然后复制代码进去,再保存为exe就可以了[GRAVATAR=http://www.birdol.com/]acb31bc1883ad280a90d8044f61b3009[/GRAVATAR]

    nobird 于 2010-5-8 0:24:29 回复

    建控制台程序,编译通过就行了…

Sorry, the comment form is closed at this time.

   
© 2011 鸟儿博客 Suffusion theme by Sayontan Sinha