原代码
#includeusing namespace std;int main(){ int m, n, s;//m为总人数,n为报数,s为刚开始报数的位置 cin >> m >> n >> s; struct Node { int data; Node* next; }; Node* first=new Node; first->data = 1; Node* current = first->next; for (int i = 2; i <= m; i++) { current = new Node; current->data = i; current = current->next; } current = first; Node* location = first; for (int j = 1; j <= m; j++) if (location->next->data == s) break; else location = location->next; Node* location1 = location->next;//location指向当前报数人的前一个人,location1指向当前报数人 for (int i = 0; i < m - 1; i++) { for (int j = 1; j <= n; j++) location = location->next; Node* location1 = location->next; location->next = location->next->next;//将报到n的人删除 delete location1; } cout << first->data; return 0;}
这是什么问题?求指点。