import java.util.Scanner;
abstract class Express{
private int weight;
public Express(int weight){
this.weight = weight;
}
public int getWeight(){
return weight;
}
abstract public int getTotal();
}
class SLExpress extends Express{
public SLExpress(int weight){
super(weight);
}
public int getTotal(){
int weight = getWeight();
if(weight<=1) return 12;
else return 12+(weight-1)*2;
}
}
class DDExpress extends Express{
public DDExpress(int weight){
super(weight);
}
public int getTotal(){
int weight = getWeight();
if(weight<=1) return 5;
else return 5+(weight-1);
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Express express; ////重点在这里!!!!!!!!
int total = 0;//定义总价
for (int i = 0; i < n; i++) {
String a = sc.next();
int b = sc.nextInt();
if(a.equals("SL")){
express = new SLExpress(b); ///重点!!!!
total+=express.getTotal();
}
if(a.equals("DD")){
express = new DDExpress(b); ///重点!!!!!
total+=express.getTotal();
}
}
System.out.println(total);
}
}
不能用
SLExpress express = new SLExpress(b);
DDExpress express = new DDExpress(b);
来写