int Node_Size ; struct Node{ int x ; Node *next ; }; Node * make_list(int n){ int i , j ; stack<int> stk ; Node *before , *root ; root = before = (Node *)malloc(sizeof(Node)) ; before->x = 1 ; before->next = NULL ; Node_Size = 1 ; for(i = 2 ; i <= n ; i++){ j = i ; while(j){ stk.push(j % 10) ; j /= 10 ; } while(!stk.empty()){ Node_Size++ ; Node *now = (Node *)malloc(sizeof(Node)) ; now->x = stk.top() ; now->next = NULL ; before->next = now ; before = now ; stk.pop() ; } } return root ; } void out(Node *root){ Node * p ; p = root ; do{ printf("%d->",p->x) ; p = p->next ; }while(p != NULL) ; puts("") ; } Node * delete_even(Node *List){ Node *root , * now , *before; root = before = List ; now = before->next ; while(before->next != NULL && now->next != NULL){ before->next = now->next ; before = now->next ; free(now) ; now = before->next ; Node_Size-- ; } if(now != NULL && now->next == NULL){ before->next = NULL ; Node_Size-- ; } return root ; } Node * delete_odd(Node *List){ Node *root , * now , *before; List = List->next ; root = List ; Node_Size-- ; root = delete_even(root) ; return root ; } int gao(int n){ Node_Size = 0 ; Node * root = make_list(n) ; int k = 1 ; while(Node_Size > 1){ // out(root) ; // cout<<Node_Size<<endl ; root = k? delete_even(root) : delete_odd(root) ; k ^= 1 ; } int ans = root->x ; free(root) ; return ans ; } class Test { public: static int remain (int n) { return gao(n); } }; //start 提示:自动阅卷起始唯一标识,请勿删除或增加。 int main() { cout<<Test::remain(0)<<endl; } //end //提示:自动阅卷结束唯一标识,请勿删除或增加。