[Programming questions] The deletion has an array of a[n] order to store 0-n, requiring no more than two numbers to delete a number, to the end of the loop to the beginning of the continuation of the last deleted number of the original subscript position. Take 8 numbers (n=7) as an example: {0,1,2,3,4,5,6,7},0->1->2 (delete)->3->4->5 (delete)->6->7->0 (delete), so loop until the last number is deleted.
Input Description:
Each set of data is an integer n (less than or equal to 1000), and the number of members of the array, such as 100, is computed for a[999].
Output Description:
The original subscript position of the last deleted number line output.
Input Example:
8
Output Example:
6
#include <iostream>#include<list>using namespacestd;intMain () {intm=2; intN; while(cin>>N) {list<int>lst; for(intI=0; i<n;i++) {lst.push_back (i); } list<int>::iterator iter=Lst.begin (); while(Lst.size () >1) { if(iter==lst.end ()) ITER=Lst.begin (); for(intI=0; i<m;i++) {iter++; if(iter==lst.end ()) ITER=Lst.begin (); } /*List<int>::iterator next=iter++; if (Next==lst.end ()) Next=lst.begin (); iter--;*/ITER=Lst.erase (ITER); } cout<<lst.front () <<Endl; } return 0;}
Huawei Machine Questions