/* cout << " *****************game by ring light**************************" << endl; cout << " **** 一个全开的循环串联灯链 为节约资源等待你的关灯动作******" << endl; cout << " *****提示: 当选择一盏灯时,该灯及旁边的灯状态均会发生变化****" << endl; cout << " *****************game by ring light**************************" << endl; 破解办法居然简单在于逐一从第一个点开关所有的灯就能实现所有的灯从全亮到全灭 */ #include <iostream> using namespace std; struct node { int data; node *prev; node *next; public: node():data(1),prev(NULL),next(NULL){} node(int a):data(a),prev(NULL),next(NULL){} }; void creat(node *list) { int n=20; node *tmp;node *tail; while(n--) { if(list->next == NULL) { tmp = new node(1); tmp->prev = list; tmp->next = list; list->prev = tmp; list->next = tmp; tail=tmp; } else { tmp = new node(1); list->next->prev = tmp; tmp->next = list->next; tmp->prev = tail; tail->next=tmp; list->next = tmp; } } } void show(node *list) { int n=20; node *p = list->next; while(n--) { //cout<<"["<<20-n<<"] "<<p->data<<" "; cout<<p->data<<" "; p=p->next; } cout<<endl; } void _play(node *list,int x) { node *p = list->next; while(x-- -1) { p=p->next; } p->prev->data=1-p->prev->data; p->data=1-p->data; p->next->data=1-p->next->data; } int check(node *list) { int n=20; node *p = list->next; while(n--) { if(p->data==1)break; p=p->next; } return 1-p->data; } void play(node *list) { int x=1; int n=40; while(n--) { cout<<"40步解灯谜之"<<40-n<<"步:(输入0~20)"<<endl<<'\t'<<'\t'; cin>>x; _play(list,x); show(list); if(n==20&&check(list))break; } } int main() { cout << " *****************game by ring light**************************" << endl; cout << " **** 一个全开的循环串联灯链 为节约资源等待你的关灯动作******" << endl; cout << " *****提示: 当选择一盏灯时,该灯及旁边的灯状态均会发生变化****" << endl; cout << " *****************game by ring light**************************" << endl; node list; creat(&list); show(&list); play(&list); show(&list); cout << " wzzx" << endl; return 0; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。