最新出炉面试题 100分

praylgjywjy 2010-10-21 07:07:07
a*b<n!,求n
大家都说说想法。。。算法
...全文
203 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
luciferisnotsatan 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 chain2012 的回复:]

必须考虑溢出,!级别的数增长很快
比如:100!= 9.3326215443944152681699238856267e+157
[/Quote]
+1
这题应该考的就是大数问题吧
chainyu 2010-10-22
  • 打赏
  • 举报
回复
必须考虑溢出,!级别的数增长很快
比如:100!= 9.3326215443944152681699238856267e+157
qq583735151 2010-10-21
  • 打赏
  • 举报
回复
利用模板元编程方法,如:
#include "stdafx.h"
#include<iostream>
using namespace std;

template<int SIZE>
class J
{
public:
enum{VALUE=J<SIZE-1>::VALUE*SIZE};
};
template<>
class J<0>
{
public:
enum { VALUE=1};
};
//用J<n>::VALUE 就可以表示n!

void main()
{
cout << J<3>::VALUE << endl;

}
kolerdck 2010-10-21
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,n;
do
{
scanf("%d%d",&a,&b);
c=1;
n=1;
do
{
c=n*c;
n++;
}while(c<(a*b));
printf("\nn=%d",n-1);
printf("\n");
}while(1);
}
無_1024 2010-10-21
  • 打赏
  • 举报
回复
应该要考虑溢出的问题吧
praylgjywjy 2010-10-21
  • 打赏
  • 举报
回复
当然没错,觉得你思维很好[Quote=引用 11 楼 yangsen600 的回复:]

引用 10 楼 praylgjywjy 的回复:
厉害啊

引用 9 楼 yangsen600 的回复:

C/C++ code

while(c)
{
c /= n;//就体现在里面两句。逆向思维。
++n; //
}

没错吧?你又更好的算法吗?看看、、、
[/Quote]
千杯不醉-sen 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 praylgjywjy 的回复:]
厉害啊

引用 9 楼 yangsen600 的回复:

C/C++ code

while(c)
{
c /= n;//就体现在里面两句。逆向思维。
++n; //
}
[/Quote]
没错吧?你又更好的算法吗?看看、、、
praylgjywjy 2010-10-21
  • 打赏
  • 举报
回复
厉害啊[Quote=引用 9 楼 yangsen600 的回复:]

C/C++ code

while(c)
{
c /= n;//就体现在里面两句。逆向思维。
++n; //
}
[/Quote]
千杯不醉-sen 2010-10-21
  • 打赏
  • 举报
回复

while(c)
{
c /= n;//就体现在里面两句。逆向思维。
++n; //
}
praylgjywjy 2010-10-21
  • 打赏
  • 举报
回复
既然简单,说说你的想法吧[Quote=引用 6 楼 lovestefanie 的回复:]

。。。。。。
好简单的题目啊
[/Quote]
praylgjywjy 2010-10-21
  • 打赏
  • 举报
回复
你是怎么想的n!体现在c/=n;上呢?[Quote=引用 5 楼 yangsen600 的回复:]

C/C++ code

#include <iostream>
using namespace std;

int main()
{
int a,b,c,n=1;
cout<<"please enter a and b"<<endl;
cin>>a>>b;
c = a * b;
while(c)
{
c /= n;
……
[/Quote]
lovestefanie 2010-10-21
  • 打赏
  • 举报
回复
。。。。。。
好简单的题目啊
千杯不醉-sen 2010-10-21
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;

int main()
{
int a,b,c,n=1;
cout<<"please enter a and b"<<endl;
cin>>a>>b;
c = a * b;
while(c)
{
c /= n;
++n;
}
cout<<a<<"*"<<b<<"<"<<n-1<<"!"<<endl;
return 0;
}
/////////////////////////////////////////
please enter a and b
1 1
1*1<2!
Press any key to continue
please enter a and b
10 10
10*10<5!
Press any key to continue
please enter a and b
12 12
12*12<6!
Press any key to continue
please enter a and b
100 100
100*100<8!
Press any key to continue
please enter a and b
100 100
100*100<8!
Press any key to continue
praylgjywjy 2010-10-21
  • 打赏
  • 举报
回复
能说说想法吧,思路。。。
shenchenman 2010-10-21
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
void main()
{
float a,b;
int intpluData=1;
cout<<"请输入a,b的值\n";
cin>>a>>b;
for(int n=1;n<=a*b;n++)
{
intpluData*=n;//求阶乘
if(intpluData>a*b)//大于a*b就跳出
{
cout<<"The result is"<<n;
break;
}
}
}
千杯不醉-sen 2010-10-21
  • 打赏
  • 举报
回复

int n = 1;
int c = a*b;
while(c)
{
c /= n;
++n;
}

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧