Huawei Machine Questions

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.