OJ Brush the problem of "pay"

Source: Internet
Author: User

<span style= "Color:blue; font-family: ' Helvetica Neue ', Helvetica, Arial, Sans-serif; font-size:24px; line-height:36px; Background-color:rgb (255, 255, 255); " >Description</span>

As SDIBT's teacher, the most expected day is the monthly number 10th, because this is the day of wages, the breadwinner depends on it, hehe but for the school Finance Department staff, this day is a very busy day, Xiao Hu, the Finance department, has recently been thinking about a question: if every teacher's salary is known, at least how many yuan to prepare, in order to pay for each teacher without teacher change? This assumes that the teacher's wages are positive integers, unit yuan, a total of 100 yuan, 50 yuan, 10 yuan, 5 yuan, 2 yuan and 1 Yuan six.

Input

The input data contains multiple test instances, and the first line of each test instance is an integer n (n<100), which indicates the number of teachers and then the wages of N teachers. N=0 indicates the end of the input and does not handle it.

Output

Output an integer x for each test instance to indicate the minimum number of renminbi to be prepared. Each output occupies one row.

Sample Input
31 2 30
Sample Output
4
HINT

The code is as follows:

#include <iostream>using namespace Std;int main () {    int n,i,num=0;    int a[100];    while (cin>>n&&n!=0)    {for        (i=0; i<n; i++)            cin>>a[i];        for (i=0; i<n; i++)        {            num+=a[i]/100;            if (a[i]%100==0)                continue;            else                a[i]%=100;            NUM+=A[I]/50;            if (a[i]%50==0)                continue;            else                a[i]%=50;            NUM+=A[I]/10;            if (a[i]%10==0)                continue;            else                a[i]%=10;            NUM+=A[I]/5;            if (a[i]%5==0)                continue;            else                a[i]%=5;            NUM+=A[I]/2;            if (a[i]%2==0)                continue;            else                a[i]%=2;            Num+=a[i];        }        cout<<num<<endl;        num=0;    }    return 0;}

Operation Result:


Greedy algorithm is very useful.


OJ Brush the problem of "pay"

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.