/*cout << " *****************game by ring light********************* " << endl; cout << " **** a full-cycle series lamp chain for saving resources wait for your turn off the light action ****** " << endl; cout << " ***** tip: when a lamp is selected, the lamp and the lamp state next to it will change." << endl; cout << " *****************game by ring light**************************" << endl; the solution is simply to switch from the first point of all the lights can be achieved all the lights from full-light to all-out */ #include <iostream>using namespace std;struct node{int data;node *prev;node * Next;public:node ():d ATA (1), prev (null), Next (null) {}node (int a):d ATA (a), prev (null), Next (null) {}}; void creat (node *list) {int n=20;node *tmp;node *tail;while (n--) {if (list->next == null) {TMP&NBSP;&NBsp;= 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 Steps to solve Riddles" <<40-n<< "Step: (Input 0~20)" <<endl<< ' \ t ' << ' t '; cin>>x; _play (list,x); &nbsP; show (list); if (N==20&&check (list)) break; }}int main () { cout << " *****************game by ring light**************************" << endl; cout << " **** a full cycle series lamp chain waiting for you to save resources to turn off the light action ****** " << endl; cout << " ***** tip: When a lamp is selected, the lights and the lights on the side will change. * * * << endl; cout << " *****************game by ring light**************************" << endl; node list;creat (&list), show (&list);p Lay (& list), show (&list);cout << " wzzx" << endl;return 0;}
Small code linked list realization Lights out Game 2