您好,登錄后才能下訂單哦!
/* cout << " *****************game by ring light**************************" << endl; cout << " **** 一個全開的循環(huán)串聯(lián)燈鏈 為節(jié)約資源等待你的關(guān)燈動作******" << endl; cout << " *****提示: 當選擇一盞燈時,該燈及旁邊的燈狀態(tài)均會發(fā)生變化****" << endl; cout << " *****************game by ring light**************************" << endl; 破解辦法居然簡單在于逐一從第一個點開關(guān)所有的燈就能實現(xiàn)所有的燈從全亮到全滅 */ #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 << " **** 一個全開的循環(huán)串聯(lián)燈鏈 為節(jié)約資源等待你的關(guān)燈動作******" << endl; cout << " *****提示: 當選擇一盞燈時,該燈及旁邊的燈狀態(tài)均會發(fā)生變化****" << endl; cout << " *****************game by ring light**************************" << endl; node list; creat(&list); show(&list); play(&list); show(&list); cout << " wzzx" << endl; return 0; }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。