注册 登录
编程论坛 C++教室

[一起来解答]相当经典的76道编程自虐题分享.无答案的哦

野比 发布于 2007-06-15 22:18, 1792 次点击

换地方了. 请大家到这里继续

https://bbs.bc-cn.net/viewthread.php?tid=147967

[此贴子已经被作者于2007-6-16 12:02:21编辑过]

18 回复
#2
yuyunliuhen2007-06-15 22:23

给我来一份,lijin157@163.com,Thank you!

#3
aipb20072007-06-15 22:24
呵呵,自虐一下:
aipb@163.com
谢谢!
#4
野比2007-06-15 22:33
两位挑战自我的达人..已送上.
#5
百年不亮2007-06-15 22:50

2. A、B、C、D、E五名学生有可能参加计算机竞赛,根据下列条件判断哪些
人参加了竞赛:

(1)A参加时,B也参加;

(2)B和C只有一个人参加;

(3)C和D或者都参加,或者都不参加;

(4)D和E中至少有一个人参加;

(5)如果E参加,那么A和D也都参加。

___________________________________________________________________

答案:

#include<stdio.h>
int main()
{
char name[]={'A','B','C','D','E'};
int i,value[5];

for(value[0]=0;value[0]<2;value[0]++)
for(value[1]=0;value[1]<2;value[1]++)
for(value[2]=0;value[2]<2;value[2]++)
for(value[3]=0;value[3]<2;value[3]++)
for(value[4]=0;value[4]<2;value[4]++)
{
if((value[1]>=value[0])
&&(value[1]+value[2]==1)
&&value[2]==value[3]
&&(value[3]+value[4])
&&(!value[4]||(value[4]&&value[0]&&value[3])))
for(i=0;i<5;i++)
if(value[i])
printf("%c参加\t",name[i]);
else
printf("%c不参加\t",name[i]);
}
return 0;

}

结果:

A不参加 B不参加 C参加 D参加 E不参加

#6
野比2007-06-15 22:55
哦...高手出现..
#7
HJin2007-06-15 22:56

Dear Sir 野比:

I am in. Email address is fish_sea_bird@yahoo.com Thanks.

By the way, how did you enter the characters, which has value bigger than 127 and less than 256, in an ASCII files? These values never appear right when I write it using C++, say


[CODE]#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv)
{
ofstream ofs("a.txt");
unsigned char c = 0xA9; // the ┌ char
ofs<<c<<endl;
ofs.close();
/**
after this, a.txt file appears to be a "?" on my compter.
*/
return 0;
}[/CODE]

#8
百年不亮2007-06-15 22:59
我以前学c语言时也看过这个,还去打印了,后来发现没有学数据结构有些题是做不出来的,上面的2是那个时候写的,然后就一直没有看这些东西.1题也和2一样用穷举法.

我的主页有完整的,排版也比较清楚:http://xzf.2000y.net/mb/2/ReadNews.asp?NewsID=352609
#9
野比2007-06-15 23:11

Wo de yingyu hen cha, dou bu hao yisi shuo...

127以后的扩展ASCII字符只能在DOS下正确显示...
除非两个字节的扩展字符正好组成一个汉字...没试过

#10
野比2007-06-15 23:19
以下是引用百年不亮在2007-6-15 22:59:24的发言:
我以前学c语言时也看过这个,还去打印了,后来发现没有学数据结构有些题是做不出来的,上面的2是那个时候写的,然后就一直没有看这些东西.1题也和2一样用穷举法.

我的主页有完整的,排版也比较清楚:http://xzf.2000y.net/mb/2/ReadNews.asp?NewsID=352609

...向你学习

#11
百年不亮2007-06-15 23:23
I am so pity to tell you that your compiler can't support the characters, which has value bigger than 127 and less than 256.
Because your compiler support MBCS(Multi-Byte Character Set) and Unicode,which include Chinese characters and others language character.
If your compiler only support ASCII,which exclude Chinese characters ,it can support the characters, which has value bigger than 127 and less than 256.
For example Visuall C++ support MBCS,but Turbo C only support ASCII.
#12
小头爸爸2007-06-15 23:29
spsjq_1314@163.com
来一份,谢谢!!
有时间琢磨琢磨!
#13
HJin2007-06-15 23:31
以下是引用百年不亮在2007-6-15 23:23:01的发言:
I am so pity to tell you that your compiler can't support the characters, which has value bigger than 127 and less than 256.
Because your compiler support MBCS(Multi-Byte Character Set) and Unicode,which include Chinese characters and others language character.
If your compiler only support ASCII,which exclude Chinese characters ,it can support the characters, which has value bigger than 127 and less than 256.
For example Visuall C++ support MBCS,but Turbo C only support ASCII.

thanks. that is very informative. I heard of Turbo C, but never used it.


#14
HCL2007-06-16 10:48
楼住也发一分给俺可以不!
ksnba--198729@163.com
#15
aipb20072007-06-16 11:27
直接把题目都贴上来吧,又不大的,最好换个新贴,排下版。给你弄个 置顶 什么的,大家就跟贴解答题目!

呵呵!
#16
野比2007-06-16 11:43
有道理
#17
yuyunliuhen2007-06-16 11:48
Good idear!
#18
yeye05212007-06-16 12:56

我也要一份 谢谢 linlei0521@hotmail.com

#19
aipb20072007-06-16 13:14
1