6.7 输入n(n<=50)个职工的工资(单位为整数元),计算工资总额。假设用现金给每位职工发工资,计算所需各种面额的人民币的最小张数(提供人民币的面额分别为100元、50元、20元、10元、5元和1元共计六种)。

鉴于测试数据已更新,已规范代码

#include<stdio.h>

int main(void)
{
  int s[50] = { 0 };
  int i = 0;
  while (scanf("%d", s + i) && s[i])  // 输入0则结束输入
    i++;
  int y100 = 0, y50 = 0, y20 = 0, y10 = 0, y5 = 0, y1 = 0;
  int y100_n = 0, y50_n = 0, y20_n = 0, y10_n = 0, y5_n = 0, y1_n = 0;
  int sum = 0;
  for (int j = 0; j < i; j++)
  {
    sum += s[j];

    y100_n = s[j] / 100;
    y50_n = (s[j] -= 100 * y100_n) / 50;
    y20_n = (s[j] -= 50 * y50_n) / 20;
    y10_n = (s[j] -= 20 * y20_n) / 10;
    y5_n = (s[j] -= 10 * y10_n) / 5;
    y1_n = s[j] - 5 * y5_n;
    y100 += y100_n;
    y50 += y50_n;
    y20 += y20_n;
    y10 += y10_n;
    y5 += y5_n;
    y1 += y1_n;
  }
  printf("总额:%d元\n",sum);
  printf("100  50   20   10   5    1    \n");
  printf("%-5d%-5d%-5d%-5d%-5d%-5d", y100, y50, y20, y10, y5, y1);


  return 0;
}

2
说点什么

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
dfsdfdsfsdfs Recent comment authors

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
最新 最旧 得票最多
提醒
dsfsdfs
游客
dsfsdfs

alert(“hello world”)

dfsdf
游客
dfsdf

fsdfs