HDOJ2021 发工资咯:)

来源:互联网 发布:郑州用友软件总代理 编辑:程序博客网 时间:2024/05/17 02:21

这道题目一次就AC了。哈哈。细心分析一下,其实一点也不难。

Post Code:

#include<iostream>using namespace std;int rmb(int s){//先定义一个函数计算一个员工工资所需的最少的人民币的张数int count=0;count=s/100;//求100快的张数int t1=s%100;int t2=t1%10;if(t1<50){//这里要分情况讨论count=count+t1/10;//t1<50时,求10块钱的张数}else if(t1>=50){count=count+1+(t1-50)/10;//t1>=50时,一张50的在加10块 的张数}switch(t2){//switch里面是求1、2、5的张数,很简单case 1:case 2:case 5:count++;break;case 3:case 4:case 6:case 7:count=count+2;break;case 8:case 9:count=count+3;break;}return count;}int main(){int n,count;int a[100];while(scanf("%d",&n)&&n!=0){int count=0;for(int i=0;i<n;i++){scanf("%d",&a[i]);count=count+rmb(a[i]);//rmb(a[i])是求每个员工薪水所需人民币的最少张数,然后for循环把所有的张数加起来}printf("%d\n",count);}return 0;}



原创粉丝点击