2014 Huawei school recruitment test simulation-calculate the maximum incremental number

Source: Internet
Author: User

 

Description:

Enter a string of numbers to find the maximum number of increments. Increment refers to the number of adjacent digits arranged from small to large. For example, if the number of increments is 2895345323 or 23, the maximum number of increments is 289,345.

Running time limit:

Unlimited

Memory limit:

Unlimited

Input:

Enter a number. By default, the number is correct, that is, it does not contain characters or spaces.

Output:

Maximum number of output increments

Sample input:

123526897215

Sample output:

2689

Answer:

 

A basic dynamic planning algorithm is implemented in C ++. The Code is as follows:

 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5     char num[50]; 6     int currentValue=0; 7     int maxValue=0; 8     while (cin>>num) 9     {10         int i=0;11         for (i=0;num[i];i++)12         {13             currentValue=currentValue*10+num[i]-‘0‘;14             if(num[i]>=num[i+1])15             {16                 if(currentValue>maxValue)17                     maxValue=currentValue;18                 currentValue=0;19             }20         }21         cout<<maxValue<<endl;22         maxValue=0;23     }24     return 0;25 }

Running result:

 

2014 Huawei school recruitment test simulation-calculate the maximum incremental number

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.