HDU 2021 Payroll:) (Java)

Source: Internet
Author: User

Problem:

Break interrupts the entire cycle; continue interrupts the cycle;

In a loop, if you want a number to be cycled again, you can use the (i--) D method.

else if (B[i]>a[j])
{
B[I]=B[I]-A[J];
ans++;
j--;
}


Salary:)Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 38716 Accepted Submission (s): 21524


Problem description as Hangzhou electric teacher, the most expected day is the monthly number 8th, because this day is the day of wages, the breadwinner depends on it, hehe
But for the staff of the school finance Office, this is a very busy day, the finance Department of Xiao Hu recently was thinking about a question: if every teacher's salary is known, at least to prepare how many yuan, 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 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 outputs an integer x for each test instance, indicating at least the number of RMB sheets that need to be prepared. Each output occupies one row.

Sample Input
31 2 30

Sample Output
4

Code:

Dish:

Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); int N;int A[]=new Int[100];while (Cin.hasnext ()) {n=cin.nextint (); if (n==0) break;else{for (int i=0;i<n;i++) a[i]=cin.nextInt (); int m,sum=0;for (int i=0;i<n;i++) {if (a[i]>=100) {sum+=a[i]/100;if (a[i]%100==0) continue;else{a[i]=a[i]%100 ; i--;}} else if (a[i]>=50) {sum+=a[i]/50;if (a[i]%50==0) continue;else{a[i]=a[i]%50;i--;}} else if (a[i]>=10) {sum+=a[i]/10;if (a[i]%10==0) continue;else{a[i]=a[i]%10;i--;}} else if (a[i]>=5) {sum+=a[i]/5;if (a[i]%5==0) continue;else{a[i]=a[i]%5;i--;}} else if (a[i]>=2) {sum+=a[i]/2;if (a[i]%100==0) continue;else{a[i]=a[i]%2;i--;}} else SUM+=A[I]/1;} SYSTEM.OUT.PRINTLN (sum);}}}

Great God:

Import java.util.*;p Ublic class Main1 {public static void main (String args[]) {Scanner cin=new Scanner (system.in); int n;in T ans;int[] a={100,50,10,5,2,1};int[] b=new int[105];while (Cin.hasnext ()) {ans=0;n=cin.nextint (); if (n==0) break;for ( int i=0;i<n;i++) B[i]=cin.nextint (); for (int. i=0;i<n;i++) {for (int j=0;j<6;j++) {if (B[i]==a[j]) {ans++;break;} else if (B[i]>a[j]) {b[i]=b[i]-a[j];ans++;j--;} Elsecontinue;}} System.out.println (ANS);}}



HDU 2021 Payroll:) (Java)

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.