算法训练 P1101

算法训练 P1101  
时间限制:1.0s   内存限制:256.0MB
    
  
  有一份提货单,其数据项目有:商品名(MC)、单价(DJ)、数量(SL)。定义一个结构体prut,其成员是上面的三项数据。在主函数中定义一个prut类型的结构体数组,输入每个元素的值,计算并输出提货单的总金额。
  输入格式:第一行是数据项个数N(N<100),接下来每一行是一个数据项。商品名是长度不超过100的字符串,单价为double类型,数量为整型。
  输出格式:double类型的总金额。
输入:
  4
  book 12.5 3
  pen 2.5 10
  computer 3200 1
  flower 47 5

输出:
  3497.500000
class prut {
   String MC;
   double DJ;
   int SL;
   public prut(String MC,double DJ,int SL){
       this.MC=MC;
       this.DJ=DJ;
       this.SL=SL;
              
   }

}
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
        int n=sc.nextInt();
        prut[] pr=new prut[n+1];
            for(int i=0;i<n;i++){
                String t1=sc.next();
                double t2=sc.nextDouble();
                int t3=sc.nextInt();
                pr[i]=new prut(t1,t2,t3);
            }
            double ans=0.0;
            for(int i=0;i<n;i++){
                ans+=pr[i].DJ*pr[i].SL;
            }
            System.out.printf("%.6f",ans);
        }
        sc.close();

    }

}
原文地址:https://www.cnblogs.com/watchfree/p/5344575.html