Huawei trial (5)

Source: Internet
Author: User

Intermediate question
Description
You have a basket with a capacity of 100 and 30 items for you. The size of each item is known. Q: How many items can be loaded into the basket?
Input Description: A row contains 30 positive integers separated by spaces, indicating the size of each item.
Output Description: a number that indicates the maximum number of items that can be loaded.

Input sample (3 items are used as samples here, and 30 items are actually read): 5 59 100
Output example: 2

Solution: Sort all items by cost-effectiveness, and prioritize cost-effectiveness. In this question, cost-effectiveness is the volume of items.

# Include <algorithm> //  Sort Function # Include <iostream> # Include <Vector> Using   Namespace  STD;  Void Main () {Vector < Int > VES ( 3 , 0  );  For ( Int I = 0 ; I < 3 ; I ++ ) CIN > Ves [I]; sort (VES. Begin (), ves. End ());  Int Sum = 0 , Num =0  ;  For ( Int I = 0 ; I < 3 ; I ++ ) {Sum + = Ves [I];  If (Sum> 100  ){  Break  ;} Num ++ ;} Cout <Num <Endl ;} 

 

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.