PAT B 1060 Eddington number (+) C + + Edition

Source: Internet
Author: User

1060. Eddington Number (25) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Chen, Yue

British astronomer Eddington is fond of cycling. It is said that in order to show off his riding skills, he also defined a "Eddington number" E, that is, to meet the e-day ride more than e-miles of the largest integer e. It is said that Eddington's own E equals 87.

Now given someone N-day bike distance, please calculate the corresponding Eddington number E (<=n).

Input format:

Enter the first line to give a positive integer n (<=105), that is, the number of days of continuous cycling; the second line gives n non-negative integers, which represents the daily ride distance.

Output format:

Gives the number of Eddington in a row for n days.

Input Sample:
106 7 6 9 3 10 8 2 7 8
Sample output:
6

Actually just start to see this question to my feeling is difficulty how can have 0.2??? Very simple, but I am really helpless to this problem, to consider too much

And then I'll just say a few examples.
1
1
0 (not 1)

5
10 9 8) 7 6
5

5
10 9 8) 7 5
4

4
5 5 5 5
4

6
5 5 5 5 5 5
4


The code is as follows
1 //1060.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <vector>7#include <algorithm>8 9 using namespacestd;Ten  One intMain () A { -vector<int>v; -  the     intn,num,j=0; -  -CIN >>N; -  +      for(intj =0; J < N; J + +) -     { +CIN >>num; A v.push_back (num); at     } -  -vector<int>::reverse_iterator ri, rbegin = V.rbegin (), rend =v.rend (); -     intSize =v.size (); -  -Sort (rbegin, rend);//sorts the elements inside the entry vector, big in front in  -     if(v[0] = = V[size-1] && size >1&& v[0] >1)//handle all equal and number greater than 1 and value greater than 1 tocout << v[0] -1<<Endl; +     Else if(v[0] = = V[size-1] && v[0] <=1)//handling of all 0 or all 1 cases -cout <<0<<Endl; the     Else if(V[size-1] > Size)//all values are greater than the total number of days *cout << Size <<Endl; $     Else if(V[size-1] = = size)//The minimum number equals the total number of daysPanax Notoginsengcout << size-1<<Endl; -     Else//General Situation the     { +          for(j =0; j<size; J + +) A         { the             if(j +1> V[j] && v[j-1] !=V[j]) +                  Break; -             Else $                 Continue; $         } -  -cout << v[j-1]-1<<Endl; the  -     }Wuyi  the     return 0; -}

PAT B 1060 Eddington number (+) C + + Edition

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.