1 条题解

  • 0
    @ 2025-10-10 15:45:26

    C :

    #include <stdio.h>
    int main(){
        int a;
        scanf("%d",&a);
        
       float q;
        if(a <= 10){
        	q = 2.5;
        }else{
        	q = 2.5 + (a-10) * 1.5;
        }
        
        printf("%.2f",q);
        return 0;
    }
    

    C++ :

    #include<iostream>
    #include<iomanip>
    using namespace std;
    int main(){
    	double x,i;
    	cin>>i;
    	if(i<=10){
    		x=2.5;
    	}else if(i>10){
    		x=2.5+(i-10)*1.5;
    	}
    	cout<<fixed<<setprecision(2)<<x<<endl;
    }
    

    Pascal :

    var n:longint;
        s:real;
    begin
      read(n);
      s:=0;
      if n<=10 then s:=2.5
       else s:=(n-10)*1.5+2.5;
       writeln(s:0:2);
    end.
    

    Java :

    import java.text.DecimalFormat;
    import java.util.Scanner;
    public class Main{
    	public static void main(String[] args) {
    		Scanner scanner=new Scanner(System.in);
    		int w=scanner.nextInt();
    		float s=0;
    		if(w<=10){
    			s= (float) 2.5;
    		}else{
    			s=(float) ((float)(w-10)*1.5+(float)2.5);
    		}
    		DecimalFormat df=new DecimalFormat("#0.00");
    		System.out.println(df.format(s));
    	}
    }
    

    Python :

    x = int( input() )
    if x <= 10:
        y = 2.5
    else:
        y = 2.5 +(x - 10) * 1.5
    
    print('%.2f' % y)
    
    
    
    
    • 1

    信息

    ID
    42
    时间
    1000ms
    内存
    512MiB
    难度
    7
    标签
    递交数
    21
    已通过
    9
    上传者