您好,登錄后才能下訂單哦!
/* 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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。