C++面试题

wpalhm 2008-07-10 08:12:03
判断学生成绩的优劣。用户输入分数,小于60分不及格,60 =< 并且 < 75及格, 75 =< 并且 < 90良好,90 <= 并且
<= 100 优秀。 要求程序中不得出现if、else、while、for、switch关健字,不得使用任何判断、循环语句、不得嵌入汇编

请给个思路!?
...全文
453 46 打赏 收藏 转发到动态 举报
写回复
用AI写文章
46 条回复
切换为时间正序
请发表友善的回复…
发表回复
yance 2008-07-11
  • 打赏
  • 举报
回复
我觉得用cmap类也可以
pustian 2008-07-11
  • 打赏
  • 举报
回复
跟37楼一样想法
S7654321 2008-07-11
  • 打赏
  • 举报
回复
学习了,牛人就是多
nickkane 2008-07-11
  • 打赏
  • 举报
回复
实际开发哪有那么多"不得"啊...bt的要命...
qinqinhao 2008-07-11
  • 打赏
  • 举报
回复
ding
ding
night_legend 2008-07-11
  • 打赏
  • 举报
回复
char* level[7]={"不及格","不及格","不及格","不及格","及格","良好","优秀"};

int score;
cin >> score;
cout < < level[score/15] < <endl;
有点取巧,呵呵
Dazzlingwinter 2008-07-11
  • 打赏
  • 举报
回复
这个有意思,呵呵!
zwh37333 2008-07-11
  • 打赏
  • 举报
回复
解法1 :递归+ 霍夫曼树 ==〉看数据结构
解法2:TMP 编程,这样也是递归的思想。
starliustar 2008-07-11
  • 打赏
  • 举报
回复
有意思,见识了
GoAssemblyNow 2008-07-11
  • 打赏
  • 举报
回复
char* level[101]={"不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","不及格","及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”,"及格”, "良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"良好“,"优秀",优秀",优秀",优秀",优秀",优秀",优秀",优秀",优秀",优秀",优秀",优秀",优秀",优秀",优秀"};

int score;
cin>>score;
cout<<level[score]<<endl;


别拍我哈!
zzstv 2008-07-10
  • 打赏
  • 举报
回复
阿欧
fejay 2008-07-10
  • 打赏
  • 举报
回复
牛人是多啊!
wpalhm 2008-07-10
  • 打赏
  • 举报
回复
厉害!csdn上真是牛人一大堆
fallening 2008-07-10
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 wpalhm 的回复:]
引用 20 楼 fallening 的回复:
还有的,模板的便特化


你能说说思路吗?
[/Quote]
template<size_t SCORE>
string result( )
{
return result<SCORE-1>();
}
template<>
string result<0>()
{
return "Fail";
}
template<>
string result<60>()
{
return "Pass";
}
template<>
string result<75>()
{
return "Good";
}
template<>
string result<90>()
{
return "Excellent";
}

这个思路如何?
bitxinhai 2008-07-10
  • 打赏
  • 举报
回复
#include<iostream.h>

void main()
{
char a[][10] = {"fail","fail","fail","fail","pass","good","excellent"};
cout<<"Enter score:"<<endl;
int score;
cin>>score;

cout<<a[score/15]<<endl;

}
这个程序也是可以的!!!!
wpalhm 2008-07-10
  • 打赏
  • 举报
回复
恩,谢谢。长见识了
iBug168 2008-07-10
  • 打赏
  • 举报
回复
不得使用任何判断、循环语句



#define __positive(x) (!((x - 1) & 0x80000000))

#define __D(x) __positive((60 - x))

#define __C(x) (__positive(x - 59) && (__positive(75 - x)))

#define __B(x) ((__positive(x - 74)) && (__positive(90 - x)))

#define __A(x) ((__positive(x - 89)) && (__positive(100 - x)))

c_result = __D(x) ? 'd' : (__C(x) ? 'c' : (__B(x) ? 'b' : 'a'));


我用abcd表示了4个等级.
鱼C缸 2008-07-10
  • 打赏
  • 举报
回复
很变态
bitxinhai 2008-07-10
  • 打赏
  • 举报
回复
void main()
{

char c[][10] = {"FAIL","PASS","GOOD","EXCELLENT"};
int score;
cout<<"Enter score:"<<endl;
cin>>score;

int a = abs((score-60))+(score-60);
int b = a?((score-60)/15.0+1):0;
cout<<c[b]<<endl;

}
这个程序基本上可以满足要求!!!
iBug168 2008-07-10
  • 打赏
  • 举报
回复

#define __positive(x) (!((x - 1) & 0x80000000))

#define __D(x) __positive((60 - x))

#define __C(x) (__positive(x - 59) && (__positive(75 - x)))

#define __B(x) ((__positive(x - 74)) && (__positive(90 - x)))

#define __A(x) ((__positive(x - 89)) && (__positive(100 - x)))

c_result = __D(x) ? 'd' : (__C(x) ? 'c' : (__B(x) ? 'b' : 'a'));
加载更多回复(26)

64,644

社区成员

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

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