📄 实验四034100549.cpp
字号:
#include <iostream.h>
#include <string>
struct node
{
char qu[100];
char s;
struct node * l;
struct node * r;
};
struct node a,b,c,d,e,f,g;
struct node * inf()
{
sprintf(a.qu,"世界人口是60亿吗?");
a.s='y';
sprintf(b.qu,"维生素c是可以辅助治疗皮肤病的吗?");
b.s='y';
sprintf(c.qu,"一天是23小时吗?\'");
c.s='n';
sprintf(d.qu,"西瓜吃多了会上火吗?");
d.s='n';
sprintf(e.qu,"手机用多了对身体好吗?");
e.s='n';
sprintf(f.qu,"现任的主席是胡锦涛吗?");
f.s='y';
sprintf(g.qu,"爱因斯坦姓爱吗?");
g.s='n';
a.l=&b;
a.r=&c;
b.l=&d;b.r=&e;
c.l=&f;c.r=&g;
d.l=d.r=e.l=e.r=f.l=f.r=g.l=g.r=NULL;
return &a;
}
char ans;
static j=0;
void show(struct node * head)
{
cout<<head->qu<<endl;
if(head->l||head->r)
{
cin>>ans;
if(ans==head->s&&head->l)
{j++;cout<<"真棒!"<<endl;
show(head->l);}
else if(ans!=head->s&&head->r)
{cout<<"答错了!再试试!"<<endl;
show(head->r);}
else
cout<<"select error"<<endl;
}
else {cin>>ans;
if(ans==head->s)
{j++;
cout<<"答对了!"<<endl;}
else
{cout<<"再想想!"<<endl;}
cout<<"游戏结束!"<<endl;
cout<<"您共答对的题数是"<<j<<endl;
}
}
int main()
{
cout<<"请回答下面的题,你认为正确的请按y,不正确的请按n"<<endl;
struct node * head=inf();
show(head);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -