http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=1177

一道简单题,对于题中所给的实数,将其转为整数以方便计算,要注意的是输出的字母部分是不要做改变的

#include<stdio.h>
struct s{
    int q,d,n,p;
}cost[10000];
int main(){
    int c[10000],j=1,i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        cost[i].q=cost[i].d=cost[i].n=cost[i].p=0;
        scanf("%d",&c[i]);
        while(c[i]>=25){
            c[i]-=25;
            cost[i].q++;
        }
        while(c[i]>=10){
            c[i]-=10;
            cost[i].d++;
        }
        while(c[i]>=5){
            c[i]-=5;
            cost[i].n++;
        }
        while(c[i]>=1){
            c[i]-=1;
            cost[i].p++;
        }
        printf("%d ",j++);
        printf("%d QUARTER(S), %d DIME(S), %d NICKEL(S), %d PENNY(S)\n",cost[i].q,cost[i].d,cost[i].n,cost[i].p);
    }
    return 0;
}

发表评论

电子邮件地址不会被公开。

Post Navigation