钱的最少张数

来源:互联网 发布:it项目团队建设 编辑:程序博客网 时间:2024/06/02 10:22

第一种:依次输出

#include <stdio.h>int main(){int k;scanf("%d",&k);while(k--){int type[]={100,50,20,10,5,1},nu=6;int cash,i,n=0;scanf("%d",&cash);for(i=0;i<nu;++i){printf("%d:%d\n",type[i],cash/type[i]);cash%=type[i];}}return 0;}

第二种:输出总的张数

#include <stdio.h>int main(){int k;scanf("%d",&k);while(k--){int type[]={100,50,20,10,5,1},nu=6;int cash,i,n=0;scanf("%d",&cash);for(i=0;i<nu;++i){n=n+cash/type[i];cash%=type[i];}printf("%d\n",n);}return 0;}


0 0
原创粉丝点击